views:

141

answers:

1

Hello, 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?

+2  A: 

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.

jcdyer
Yes and yes, especially the second part. If you've got a model with 50 fields, you've either got a number of objects tied into one model or one model that should be using one-to-many fields.
Tom