Reputation: 514
I have typical django model form and I want to hide one readonly field if its value is None and show if it has any value. Also this field is declared in Admin class, not on form.
class DjangoAdmin(admin.ModelAdmin):
from = DjangoForm
readonly_fields = ("my_field",)
fieldsets = (
("Title", {
"fields": ("my_field",)
}
)
)
def get_my_field():
value = None
if ...:
value = 1
return value
Upvotes: 1
Views: 172
Reputation: 1394
You can apply filter in get_queryset as below...
class DjangoAdmin(admin.ModelAdmin):
--- your code and logic ---
def get_queryset(self, request):
return super().get_queryset(request).exclude(my_field=None)
Now, you will only get those data in which my_field value is not a None. :)
Upvotes: 1