Reputation:
I am a python/django newbie trying to accomplish the task below. Any help will be greatly appreciated. I have a model with around 50 or so fields. I need to break them up and provide a wizard like functionality.
class ABC(models.Model): field_1 = models.IntegerField('Field 1') field_2 = models.CharField('Field 2') .. .. field_50 =
Now in my view I create several forms with a subset of the fields like so
class WizardPage1(forms.ModelForm):
def clean(self):
cleaned_data = self.cleaned_data
return cleaned_data
class Meta:
model = ABC
fields = ('field_1', 'field_2', 'etc')
class WizardPage2(forms.ModelForm):
def clean(self):
cleaned_data = self.cleaned_data
return cleaned_data
class Meta:
model = ABC
fields = ('field_11', 'field_12', 'etc')
When I create a FormWizard with say 5 forms, 5 records get stored. My question is how do I save this into one record?
Upvotes: 0
Views: 1156
Reputation: 19165
The problem is not in your form definitions, but in how you are calling them. When you call WizardPage2
, you need to pass in the instance of your model which was saved by WizardPage1
, so that it is operating on the proper object.
Also, your model should almost definitely be split into several tables. I can't think of an well-designed object complex enough in itself to need 50 fields. Look for separate areas of functionality, and separate them out into other models. It will make your life easier.
Upvotes: 2