Created
November 3, 2020 21:20
-
-
Save egitimplus/0d0c5becbc05338c5e003424743f80de to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
class FuelType(models.Model): | |
name = models.CharField(max_length=255) | |
def __str__(self): | |
return self.name | |
class CarModel(models.Model): | |
name = models.CharField(max_length=255) | |
fueltype = models.ManyToManyField(FuelType, related_name='models', through='ModelFuel') | |
def __str__(self): | |
return self.name | |
class ModelFuel(models.Model): | |
fueltype = models.ForeignKey(FuelType, on_delete=models.CASCADE) | |
carmodel = models.ForeignKey(CarModel, on_delete=models.CASCADE) | |
name = models.CharField(max_length=255) | |
def __str__(self): | |
return self.name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment