Custom Inline Forms with InlineFormsets

501 views
Skip to first unread message

John Boxall

unread,
Nov 10, 2008, 3:47:03 PM11/10/08
to Django users
Heyo Django Users,

I'm in a bit of a pickle with InlineFormsets -

I'm following the example at the Django Docs:
http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#using-inlineformset-factory

I've got two models:
--------------------
class Author(models.Model):
name = models.CharField(max_length=100)

class Book(models.Model):
author = models.ForeignKey(Author)
title = models.CharField(max_length=100)
description = models.CharField(max_length=255)
--------------------

And I want to have an inline formsets to edit authors & books inline.

What I want to do is just show the title field of the Book so I have
a custom ModelForm for that:

--------------------
class BookModelForm(forms.ModelForm):
class Meta:
model = Book
fields = ('title',)
--------------------

Everything looks good, I'm all ready to construct my
inlinemodelformset using inlineformset_factory...
--------------------
from django.forms.models import inlineformset_factory
# ???
BookFormSet = inlineformset_factory(Author, Book)
--------------------

And doh! inlineformset_factory doesn't seem to want to let me set the
form for the inline model.
http://code.djangoproject.com/browser/django/trunk/django/forms/models.py

Anyone have any luck with this?

Thanks,

John

John Boxall

unread,
Nov 10, 2008, 3:49:20 PM11/10/08
to Django users
I take it back.

I over thought it -

Instead of using a custom inline form model just pass the parameters
directly to inlineformset_factory as per it's spec:
def inlineformset_factory(parent_model, model, form=ModelForm,
formset=BaseInlineFormSet, fk_name=None,
fields=None, exclude=None,
extra=3, can_order=False, can_delete=True,
max_num=0,
formfield_callback=lambda f:
f.formfield()):

On Nov 10, 12:47 pm, John Boxall <bisha...@gmail.com> wrote:
> Heyo Django Users,
>
> I'm in a bit of a pickle with InlineFormsets -
>
> I'm following the example at the Django Docs:http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#using-i...
> form for the inline model.http://code.djangoproject.com/browser/django/trunk/django/forms/model...

Ben Gerdemann

unread,
Nov 17, 2008, 10:16:20 AM11/17/08
to Django users
I'm having a similar problem that I posted about here:

http://groups.google.com/group/django-users/browse_thread/thread/bb4c792f13b2eceb#

Did you find a solution that works for you? Sorry, I couldn't figure
out from your post exactly what you did. I tried using
inlineformset_factory() like you described, but I couldn't get it to
work. Are you working inside the admin interface? Perhaps that is my
problem....

Cheers,
Ben

On Nov 10, 6:49 pm, John Boxall <bisha...@gmail.com> wrote:
> I take it back.
>
> I over thought it -
>
> Instead of using a custominlineform model just pass the parameters
> > form for theinlinemodel.http://code.djangoproject.com/browser/django/trunk/django/forms/model...
Reply all
Reply to author
Forward
0 new messages