Django: Reload Form Data After Db Values Change
I have a Django form that generates input 'number' fields from values of database with storehouse items. After processing all the input data is stored in a temporary database. Beca
Solution 1:
You should add fields in the __init__()
method of a form:
class StorehouseItems(forms.Form):
def __init__(self, *args, **kwargs):
super(StorehouseItems, self).__init__(*args, **kwargs)
for key in Storehouse.objects.all():
field = str(key.pk)
label = "%s<br />(max %s%s)" % (key.name, key.amount, key.prefix)
self.fields[field] = forms.IntegerField(label=label,
min_value=0,
max_value=key.amount,
required=False)
Post a Comment for "Django: Reload Form Data After Db Values Change"