I have a view where if request.method == 'POST', I need to call save. Basically, it's a registration form and the entity is a user (not the base Django user, but a custom model). An existing user refers another person, when they click the link they come to a registration page.
I have a problem where I try to call save:
form = SubmitReferralForm(data=request.POST)
if form.is_valid():
try:
registered_user.referral_set.get(email_address=form.instance.email_address, status=1)
msg = 'This email address has already been referred. Try another?'
except Referral.DoesNotExist:
form.instance.status = 1
referral = form.save()
The form looks as follows:
class SubmitReferralForm(forms.ModelForm):
class Meta:
model = Referral
exclude = (
'section', 'referrer', 'status', 'time_added',
)
Now, the section referred to here is hideen in the form but I need to provide it before calling save. Problem is, the referred user's section is in one app, the referrer's section is in another - but they should both be the same. The exception is:
Exception Value:
(1048, "Column 'section_id' cannot be null")
... it is raised here ...
referral = form.save()
Any ideas on overcoming this behaviour?
Thanks!
--
Regards,
Sithembewena Lloyd Dube
--
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 django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
No comments:
Post a Comment