Re: More Than Two Models With inlineformset_factory

2009-08-12 Thread Geraldo

No, I mean two or more different forms.  I'd like Parent, Child1 AND
Child2 all in the same formset.  What you've suggested though, should
get me where I want to go.

Thanks again,
Gerry

On Aug 12, 12:53 am, Matthias Kestenholz
 wrote:
> On Wed, Aug 12, 2009 at 12:51 AM, Geraldo wrote:
>
> > Excellent, Matthias...  That should work nicely.  It does appear,
> > however, that there is no way to have more than 2 forms in a single
> > formset.  If inlineformset_factory had an append method things might
> > be a bit cleaner.
>
> I presume you mean more than two forms of the same type (Child1 or
> Child2)? That's easily possible, and we use it all the time. Take a
> look at the max_num and extra parameters to the factory function.
>
> Matthias
>
> --
> FeinCMS Django CMS building toolkit:http://spinlock.ch/pub/feincms/
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: More Than Two Models With inlineformset_factory

2009-08-11 Thread Geraldo

Excellent, Matthias...  That should work nicely.  It does appear,
however, that there is no way to have more than 2 forms in a single
formset.  If inlineformset_factory had an append method things might
be a bit cleaner.

Thanks again for your help.
geraldo

On Aug 11, 3:55 pm, Matthias Kestenholz
 wrote:
> On Tue, Aug 11, 2009 at 10:04 PM, Geraldo wrote:
>
> > Hi,
>
> > I'm new to Django and am putting together a page for my new site.  I
> > want to be able to edit data that is contained in 3 models, organized
> > as follows:
> > Parent
> >  --> Child 1 (always one to one)
> >  --> Child 2 (one or more)
>
> > I understand I can do the following:
>
> > class Parent(models.Model):
> >    name = models.CharField(max_length=100)
> >    parent_type = models.CharField(max_length=10)
>
> > class Child1(models.Model):
> >    name = models.ForeignKey(Author)
> >    address = models.CharField(max_length=100)
>
> > class Child2(models.Model):
> >    name = models.ForeignKey(Author)
> >    gender = models.CharField(max_length=8)
>
> > # so I can do this to get a formset with Parent and Child1
> > Formset1 = inlineformset_factory(Parent, Child1)
> > dad = Parent.objects.get(name=u'Popeye')
> > formset = Formset1(instance=dad)
>
> > # or this to get a formset with Parent and Child2
> > Formset2 = inlineformset_factory(Parent, Child2)
> > dad = Parent.objects.get(name=u'Popeye')
> > formset = Formset2(instance=dad)
>
> > What I don't understand is how I get both child1 and child2 in my
> > formset?
>
> You can pass a prefix parameter when constructing the formsets (not
> the formset classes):
>
> Formset1 = inlineformset_factory(Parent, Child1)
> Formset2 = inlineformset_factory(Parent, Child2)
>
> if request.method == 'POST':
>     child1_formset = Formset1(request.POST, ..., prefix='child1')
>     child2_formset = Formset2(request.POST, ..., prefix='child2')
> else:
>     child1_formset = Formset1(..., prefix='child1')
>     child2_formset = Formset2(..., prefix='child2')
>
> This prefix will be added to all formset fields automatically. The
> browser and Django will be able to differentiate between the two
> formsets now.
>
> Matthias
>
> --http://spinlock.ch/pub/feincms/
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



More Than Two Models With inlineformset_factory

2009-08-11 Thread Geraldo

Hi,

I'm new to Django and am putting together a page for my new site.  I
want to be able to edit data that is contained in 3 models, organized
as follows:
Parent
 --> Child 1 (always one to one)
 --> Child 2 (one or more)

I understand I can do the following:

class Parent(models.Model):
name = models.CharField(max_length=100)
parent_type = models.CharField(max_length=10)

class Child1(models.Model):
name = models.ForeignKey(Author)
address = models.CharField(max_length=100)

class Child2(models.Model):
name = models.ForeignKey(Author)
gender = models.CharField(max_length=8)

# so I can do this to get a formset with Parent and Child1
Formset1 = inlineformset_factory(Parent, Child1)
dad = Parent.objects.get(name=u'Popeye')
formset = Formset1(instance=dad)

# or this to get a formset with Parent and Child2
Formset2 = inlineformset_factory(Parent, Child2)
dad = Parent.objects.get(name=u'Popeye')
formset = Formset2(instance=dad)

What I don't understand is how I get both child1 and child2 in my
formset?

Any help would be greatly appreciated.  Thanks so much in advance!
geraldo


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