Thanks Richard that seems like a much more logical way of doing it.

Works with one slight change:

form_data = request.POST.copy()
form_data['domain_id'] = domain_id

form = DNSRecordForm(form_data)
if form.is_valid():
      form.save()


Paddy

On Sep 27, 11:35 am, Richard Dahl <[EMAIL PROTECTED]> wrote:
> Off the top of my head, how about something like this:
>
> form_data = request.POST
> form_data['domain_id'] = domain_id
>
> form = DNSRecordForm(form_data)
> if form.is_valid():
>       form.save()
>
> I think you should get the idea.  Obviously the DNSRecordForm will
> have to have the domain field in it.
> -richard
>
> On Sep 26, 2007, at 8:30 AM, Paddy Joy wrote:
>
>
>
> > Is there a way I can validate form data after doing
> > form.save(commit=False)?
>
> > I am using (commit=False) because I want to set the model ForeignKey
> > after the data has been posted, for example here is my view:
>
> > def domain_dnsrecords(request, domain_id):
>
> >    DNSRecordForm = forms.form_for_model(DNSRecord,
> > fields=('name','type','data','aux','ttl'))
>
> >    if request.method == 'POST':
>
> >                    form = DNSRecordForm(request.POST)
>
> >            dnsrecord = form.save(commit=False)
>
> >            dnsrecord.domain_id = domain_id
>
> >            dnsrecord.save()
>
> >            return HttpResponseRedirect("/hosting/domain/dnsrecords/%i/" %
> > int(domain_id))
>
> >    else:
> >                    form = DNSRecordForm()
>
> >    dnsrecords = DNSRecord.objects.filter(domain=domain_id)
>
> >    return render_to_response('hosting/dnsrecords.html', {'dnsrecords':
> > dnsrecords, 'dnsrecordform': form})
>
> > After setting the foreign key (domain_id) I would like to check the
> > complete data to see if it is valid.
>
> > Any ideas?
>
> > Paddy


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to