On Jul 21, 2009, at 12:49 PM, mettwoch wrote:

>
> Sorry my old brain doesn't get it. Is there somewhere a complete CRUD
> example using ModelForm?
>
> Thanks
> Marc

CRUD:

If your modelform is called PartnerForm, then.

CREATE and UPDATE:

        #on initial page load (no POST)
        
        #if you have a partner object already (named partner_instance):
        partner_form = PartnerForm(instance = partner_instance)
        #otherwise:
        partner_form = PartnerForm()

        #in the POST portion of your view
        partner_form = PartnerForm(request.POST)
        if partner_form.is_valid():
                partner_form.save()

DELETE:
        #if you have a partner object named partner_instance
        partner_instance.delete()

READ:
        What do you mean?
        Partner.objects.get(pk = 12) #or whatever
        
        #or, from the modelform instance, assuming
        #something like partner_form = PartnerForm(instance = partner_instance)
        #has happened:
        if partner_form.is_valid():
                partner_name = partner_form.cleaned_data['name']
        
I hope this helps. If not, please be more specific.
        


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
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