Looks like my models are working. (YAY!!!!!) My save routine failed though, but I finally figured it out. So the done() function looks like this now:
def done(self, request, form_list): o = PurchaseApplication() for form in form_list: form.instance = o form.save(commit=False) o.site = Site.objects.get_current() o.save() Inheriting from a form doesn't seem to work. But I'll work on that... class A(ApplicationForm) class B(A) <-- not working - fields don't populate from parent obj On Aug 23, 9:40 pm, lingrlongr <[EMAIL PROTECTED]> wrote: > It looks like these ModelForms are going to work well for me. I have > a lot less code now. I actually created 2 other classes to help out > with the field ordering. I haven't tested these yet... > > class OrderedForm(ModelForm): > def __init__(self, ordered_fields, *args, **kwargs): > super(OrderedForm, self).__init__(*args, **kwargs) > self.fields.keyOrder = ordered_fields > for f in self.fields: > self.fields[f].label = self.fields[f].help_text > self.fields[f].help_text = None > > class ApplicationForm(OrderedForm): > def __init__(self, *args, **kwargs): > try: > ordered_fields = list(self.Meta.fields) > except: > ordered_fields = [] > super(ApplicationForm, self).__init__(ordered_fields, *args, > **kwargs) > > I'll just inherit from ApplicationForm for all my forms. I'm not sure > how its going to work with ModelForm inheritance yet though... > > I don't understand how I'm going to use this forms with the form > wizard though, particularly in the done() function. Each form in the > wizard contains some of the fields for the model. > > o = MyObject() > > for form in form_list: > f = form_list[form](instance=o) > f.save(commit=False) > > o.site = Site.objects.get_current() > o.save() > > Does this look right? Thanks for everyone's help so far!! > > Keith > > On Aug 23, 3:45 am, coulix <[EMAIL PROTECTED]> wrote: > > > 1. yes by overlriding the init > > > class myForm(forms.ModelForm): > > def __init__(self, *args, **kwargs): > > super(myForm, self).__init__(*args, **kwargs) > > self.fields.keyOrder = ['foo', 'bar',...] > > > 2. in the same way you could use > > self.fields['foo'].label = self.fields['foo'].help_text > > > On Aug 22, 10:40 pm, lingrlongr <[EMAIL PROTECTED]> wrote: > > > > So by using a combination of fields and exclude in the Meta class, I > > > can choose what fields I want for that form. Nice! :) > > > > Two questions though: > > > > 1. Will fields be presented in the order specified in the fields > > > tuple? > > > 2. In my original model/form diagram, will there be a way for me to > > > use the model's help_text as the field label? > > > > Keith > > > > On Aug 22, 4:24 pm, lingrlongr <[EMAIL PROTECTED]> wrote: > > > > > Ah, so I guess ModelForm will work with the FormWizard? I'll have to > > > > look through that documentation. Reading documentation is easier than > > > > pulling my hair out! =) > > > > > Thanks Rajesh. > > > > > On Aug 22, 4:14 pm, Rajesh Dhawan <[EMAIL PROTECTED]> wrote: > > > > > > Hi Keith, > > > > > > > I'm using the form wizard for a project. All the field names in > > > > > > models.py coincide with the field names in forms.py. There is ONE > > > > > > field that is consistently, yet sporadically, causing problems and I > > > > > > cannot see why. > > > > > > > # models.py > > > > > > class PurchaseApplication(BasicApplication): > > > > > > down_payment_assets = models.IntegerField(help_text=u'Available > > > > > > assets for down payment') > > > > > > > # forms.py > > > > > > class PurchaseForm3_yes(forms.Form): > > > > > > down_payment_assets = forms.IntegerField(label=u'Available > > > > > > assets > > > > > > for down payment ($)') > > > > > > > So, as I said, all the field names for the model and the form, so to > > > > > > save I use: > > > > > > > class PurchaseWizard(FormWizard): > > > > > > def done(self, request, form_list): > > > > > > data = {} > > > > > > for f in form_list: > > > > > > data.update(f.cleaned_data) > > > > > > > o = PurchaseApplication() > > > > > > > for f in data: > > > > > > o.__setattr__(f, data[f]) > > > > > > o.site = Site.objects.get_current() > > > > > > o.save() > > > > > > > So, its only the down_payment_assets field that is causing problems, > > > > > > but only sporadically. The error text looks like this: > > > > > > > Exception Type: OperationalError > > > > > > Exception Value: (1048, "Column 'down_payment_assets' cannot > > > > > > be > > > > > > null") > > > > > > > But the request.POST vars in actally show a value!! > > > > > > > Variable Value > > > > > > 1-credit_rating u'1' > > > > > > 2-purchase_home_type u'1' > > > > > > 2-down_payment_assets u'30000' > > > > > > <----------------------------- > > > > > > 0-best_time u'1' > > > > > > 1-contact_me u'N' > > > > > > wizard_step u'2' > > > > > > > Thoughts? > > > > > > Looks like o.__setattr__(f, data[f]) is not doing it's job for the > > > > > field down_payment_assets. You might want to print or log what's in > > > > > 'data' before you iterate over it. > > > > > > Also, are you aware that Django's built-in ModelForm provides similar > > > > > functionality to what you seem to be trying to achieve above? > > > > > >http://www.djangoproject.com/documentation/modelforms/ > > > > > > -Rajesh D --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---