Well, either I'm not able to follow your example or we are talking
about different things.  In any case here is what I got working as a
first draft.  As a big benefit to me is the fact that I now understand
these inner workings a little better.  I was hoping to get away with
simple wrappers to generic views but now I don't think that will be
the case but it also doesn't worry me.  :)

This is closely adapted from:  http://code.pui.ch/2007/01/07/using-
djangos-newforms/

from django import newforms as forms
from django.newforms import widgets
from django.template import loader, Context
from django.http import HttpResponse

def create_update_animal(request, animal_id=None):
    animal = None
    if animal_id:
        animal = Animal.objects.get(id=animal_id)
        animal_form = forms.models.form_for_instance(animal)
    else:
        animal_form = forms.models.form_for_model(Animal)

    if animal:
        available_protocols = Protocol.allowed_for_animal(animal)
    else:
        available_protocols = Protocol.active_list()

    protocol_choices = [('','--------')] + [(p.id,p.number) for p in
available_protocols]
    animal_form.base_fields['protocol'].widget.choices =
protocol_choices
    if animal:
        animal_form.base_fields['protocol'].widget.initial =
animal.protocol_id

    if request.method == 'POST':
        form = animal_form(request.POST)

        if form.is_valid():
            form.save()
            return HttpResponseRedirect("/")
    else:
        form = animal_form()
    t = loader.get_template('tracker/animal_form.html')

    c = Context({ 'form': form, })

    return HttpResponse(t.render(c))


If there is a way to do the above just using limit_choices_to, I'd
still like to understand that method.  Also if I'm doing anything
particularly hacky feel free to mock me (but also instruct me as to a
better way).

thanks.


On Jan 30, 5:04 pm, "quentinsf" <[EMAIL PROTECTED]> wrote:
> Sorry, the reference to 'Display' should have been to 'MyObject'


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