[Answer]-Save many to many fields in django view in a certein order

1👍

I would redesign your models as such:

class Color(models.Model):
    color = models.CharField(max_length=30)

class Car(models.Model):
    brand = models.CharField(max_length=30)
    color = models.ManyToManyField(Color)


class Lot(models.Model):
    address = models.CharField(max_length=100)
    cars = models.ManyToManyField(Car)

This leaves Cars related to Lote, and Colors by extension, but ensures that Colors are properly linked to Cars.

👤Joseph

Leave a comment