0

I have a Person model:

    class Person(models.Model):
        name = models.CharField(max_length=100)

And then a Car model:

    class Car(models.Model):
        plate = models.CharField(max_lenght=100)
        owner = models.ForeignKey(Person)

And then a certain CarAttribute model:

    class CarAttribute(models.Model):
        whatever = models.CharField(max_lenght=100)
        car = models.ForeignKey(Car)

Person has a relation 1 to many to Car. Car has a relation 1 to many to Car attributre.

Is there a way in Django for adding the Car (and eventually its relative CarAttributes) in the Form to be used when adding a new Person? One person may have more than one car, and one car can multiple attributes.

Any hints on how to approach this solution with Django? Or complementary tool?

  • You need to use fomsets. Check links to the nested formsets implementation here: https://stackoverflow.com/questions/20894629/django-nested-inline-formsets – neverwalkaloner Jan 04 '18 at 16:18
  • Also related: https://stackoverflow.com/questions/15646323/how-to-make-master-detail-model-screen-in-django – dani herrera Jan 04 '18 at 16:21

0 Answers0