python - Django - ManyToMany relation without the cross table -
i have 2 models: city , service. each city record can contain many services , each service can linked each city.
class city(models.model): name = models.charfield(max_length=255, unique=true) class service(models.model): name = models.charfield(max_length=255, unique=true) class cityservice(models.model): city = models.foreignkey(city) service = models.manytomanyfield(service)
i use manytomanyfield enable multiple selections in django admin. django creates 1 more table store m2m relations..
is possible configure django models reach following table structure:
+----+---------------+------------+ | id | city_id | service_id | +----+---------------+------------+ | 1 | 1 | 1 | | 2 | 1 | 2 | | 3 | 2 | 3 | +----+---------------+------------+
why not use structure like:
class service(models.model): name = models.charfield(max_length=255, unique=true) class city(models.model): name = models.charfield(max_length=255, unique=true) service = models.manytomanyfield(service)
Comments
Post a Comment