[BangPypers] Dynamic choices for django modelformset
Asif Jamadar
asif.jamadar at rezayat.net
Thu Oct 27 10:32:40 CEST 2011
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?
More information about the BangPypers
mailing list