user146297
user146297

Reputation: 57

Django Forms With foreign key

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.

Upvotes: 0

Views: 2538

Answers (1)

rob
rob

Reputation: 37644

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.

Upvotes: 2

Related Questions