Sunday, April 19, 2015

inlineformset_factory displays only inline formset, doesn't show parent model

I have this:

# consider all importations done right.

def add_noodle(request):
    NoodleFormSet = inlineformset_factory(Noodle, tutImages, form=NoodleForm, fields=('title', 'image'))
    if request.method == 'POST':
        formset = NoodleFormSet(request.POST, request.FILES)
        if formset.is_valid():
            formset.save()
    else:
        formset = NoodleFormSet()
    return render_to_response('add_noodle.html', {
        'formset': formset,
        })

I only get 3 tutImages model rendered in the template, without the Noodle model showing. I've been reading this: https://docs.djangoproject.com/en/dev/topics/forms/modelforms/ but don't seem to get what it means or what its trying to say with regards to the inlineformsets_factory.

I read the part 
NoodleFormSet = inlineformset_factory(Noodle, tutImages, form=NoodleForm, fields=('title', 'image'))

as

'Create an inline factory using tutImages Model (3 of them, alterable using the extra=n param) under Noodle model, using NoodleForm (which tells it the fields of Noodle model to expose to template)'

That doesn't work right. I'm missing something? Please help. Thanks


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/7a5289a3-d5b6-419f-856a-32c9322fc1de%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment