[BangPypers] Dynamic choices for django modelformset

Asif Jamadar asif.jamadar at rezayat.net
Tue Nov 1 09:36:56 CET 2011


Any suggestions for this question?

-----Original Message-----
From: bangpypers-bounces+asif.jamadar=rezayat.net at python.org [mailto:bangpypers-bounces+asif.jamadar=rezayat.net at python.org] On Behalf Of Asif Jamadar
Sent: Thursday, October 27, 2011 11:33 AM
To: BangPypers at python.org
Subject: [BangPypers] Dynamic choices for django modelformset

How can I add dynamic choices for model formset?

Suppose I have model called TestModel

Class TestModel(models.Model)

                dropdown_field =  models.CharField(max_length=70, blank=True, null=True, choices=' What to write here because my choices are dynamic')



And from this model  I want to generate modelformset of 8 forms. So I will generate 8 dropdownfields, those will have different choices.

I tried overriding the init method of BaseModelFormset and I generated dynamic choices. But when I'm trying to submit these 8 forms I'm getting validation error that "choices are not valid" because my model doesn't know about these choices. So can I define choices for model?




_______________________________________________
BangPypers mailing list
BangPypers at python.org
http://mail.python.org/mailman/listinfo/bangpypers


More information about the BangPypers mailing list