On Fri, Jun 19, 2009 at 5:01 PM, Sonal Breed <[email protected]> wrote:
>
> Hi all,
> I am trying to display a formset in my application such that it only
> contains number of forms equal to number of database instances.
>
> My models are as below:
> class Card(models.Model):
> name = models.CharField(max_length=20, blank=False, null=False,
> unique=True)
> def __str__(self):
> return self.name + " Card"
>
> class CardRow(models.Model):
> card = models.ForeignKey(ContactCard, related_name='data')
>
> name = models.CharField(max_length=22, blank=False, null=False)
> phone1 = models.CharField(max_length=20, blank=True)
> relation=models.CharField(max_length=30, blank=True)
> location=models.CharField(max_length=30, blank=True)
>
> My forms are:
> class CardForm(forms.ModelForm):
> class Meta:
> model = Card
>
> class CardRowForm(forms.ModelForm):
> class Meta:
> model = CardRow
> exclude = ('card',)
>
> CardRowFormSet = inlineformset_factory(Card, CardRow,max_num=10,
> extra=10)
>
(Note the forms you mention above aren't being used when you create
CardRowFormSet. As they are no different from what you're going to get by
default that's no problem but I'm not sure why you have created these forms
at all?)
>
> I want in the formset, the number of forms to be equal to number of
> rows per card.
> I have tried many combinations for max_num and extra fields, but in
> vain.
>
> Can somebody throw light on this issue??
>
Specify extra=0, since you don't want any extra forms and extra defaults to
3. You don't need to specify anything for max_num as by default the number
of inline forms will be determined by the number of CardRows that exist for
the Card instance you specify when you instantiate the formset.
Karen
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---