Answer the question
In order to leave comments, you need to log in
How to show fields of one model dynamically in Django admin?
Hello. There is a need to hide some fields in the admin panel of the page model. If this is the main page, then show all fields, if not the main page, then hide some fields. That is, when editing or adding pages through the admin panel, some fields were hidden on all pages except the main one. How to implement this?
Answer the question
In order to leave comments, you need to log in
class SomeModelAdmin(admins.ModelAdmin):
fields = [...] # Набор полей для всех страниц
def get_fields(self, obj):
fields = super().get_fields(obj)
if obj.main:
self.fields += [...] # Поля только для главной страницы
return fields
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question