I'm writing a view to edit a model that has ManyToMany fields.   The
form appears with all the fields  properly filled out based on the
existing model instance, except the ManyToMany fields show all the
options but none are selected. My question is, what do I have to do to
have the form appear exactly as it was when this model was first
saved? Thanks.

def edit(request, event_id):

    event = Event.objects.get(
            id=event_id
        )

    if request.method == 'POST':

        formEvent = EventModelForm(request.POST, instance=event)

        if formEvent.is_valid():


            formEvent.save()

            request.notifications.create('Success editing event.',
'success')

            return HttpResponseRedirect('/search/saved/
event_browse_upcoming/')


    else:
        # pass dict as initial
        formEvent = EventModelForm(instance = event)

    return render_to_response('event/edit_event.html', {
        'formEvent': formEvent,
        'event': event,
    }, context_instance=RequestContext(request))
--~--~---------~--~----~------------~-------~--~----~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to