7
7
7a-6662020-02-24 12:12:31
Django
7a-666, 2020-02-24 12:12:31

How to specify dependency between fields?

For example, in the model there are 2 fields, one of them is BooleanField, how to make it so that if it is true, then the 2nd field is displayed in the admin panel, and if the fall 2 is not displayed

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2020-02-24
@7a-666

@admin.register(SomeModel)
SomeModelAdmin(admin.ModelAdmin):
    def get_fields(self, request, obj=None):
        fileds = super().get_fields(request, obj)
        if obj and not obj.first_field:
            fields.remove('second_field_name')
        return fields

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question