views:

231

answers:

1

Hi, I have 2 models in django, and im also using ModelForm, my question is the second model have a froreignkey of the 1, and i want to have one page when generating the form. It's possible, how to link the two forms in one page.

Class Event(models.Model):
  id = models.AutoField(primary_key=True)
  name = models.CharField()

class Date(models.Model):
   id = models.AutoField(primary_key=True)
   start = models.DateTimeField()
   end = models.DateTimeField()
   event = models.ForeignKey("Event")

I also have

class EventForm(ModelForm)
Class Date(ModelForm)

What i want is to create the event in one page in my templates.

Thanks.

+1  A: 

If you want to have this on the Django Admin, then you need to use inline models.
If you plan to create your own form (using ModelForms), then you need to use inline formets.

Roberto Liffredo
Thank you, i will try, i whant to create my own form without using the django Admin
i tried but when i want to create an event, i got a form just with the start and end 3 times, the name is not displayed. Thanks.EventInlineFormSet = inlineformset_factory(Event, Date)and i create the formset like a form.