Answer the question
In order to leave comments, you need to log in
How to hide some option in Django select?
There is a list of choices in models.py that is displayed via the form.py page, but some options need not be displayed. How to do? Options with JS are not suitable.
class EventForm(ModelForm):
class Meta:
def sort():
status = []
for i in Event.PROBLEM_CHOICES_STATUS:
if i[0] == 1 or i[0] == 2:
status.append(i)
return status
Event.PROBLEM_CHOICES_TYPE = sort()
model = Event
fields = ( 'status', )
Answer the question
In order to leave comments, you need to log in
You can check the transmitted options at the view level and then they will not get into the page in principle.
In principle, it doesn’t matter where you will do the check, the main thing is that you have something like:
choices = [1, 2]
if not false:
choices.append(3)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question