how to override options of choices in django model form

54 views
Skip to first unread message

Sujata Aghor

unread,
Jul 28, 2020, 8:53:32 AM7/28/20
to django...@googlegroups.com
Hello All,

How can I override options of choices in django model form from the model field ?
Below is my code - 

models.py:

class XXX(models.Model):
StatusType = models.TextChoices('StatusType', const.status_values)
status = models.CharField(max_length=100, default='abc', choices=StatusType.choices,)


views.py:

class XXXUpdateView(LoginRequiredMixin, UserPassesTestMixin, UpdateView):
    model = XXX
    fields = ['aaa', 'bbb', 'status']
        
    def get_form(self):
        form = super().get_form()
        form.title = self.kwargs['title']
       # NOW HERE I WANT TO RESET THE VALUE OF STATUS DROPDOWN BASED ON CERTAIN CONDITION.
        return form
-- 

Can anyone suggest something 
Thanks in advance !

Thanks & Regards!
Sujata S. Aghor

Reply all
Reply to author
Forward
0 new messages