Skip to content

Instantly share code, notes, and snippets.

View egitimplus's full-sized avatar
😀

jure egitimplus

😀
View GitHub Profile
from django.db import models
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.fields import GenericRelation
from django.contrib.contenttypes.models import ContentType
class Car(models.Model):
name = models.CharField(max_length=255)
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
object_id = models.PositiveIntegerField()
from django.db import models
from polymorphic.models import PolymorphicModel
class Drive(PolymorphicModel):
name = models.CharField(max_length=255)
class TwoWheelDrive(Drive):
pass
from django.db import models
from polymorphic.models import PolymorphicModel
class Audio(PolymorphicModel):
name = models.CharField(max_length=255)
class Sony(Audio):
pass
from django.db import models
class FuelType(models.Model):
name = models.CharField(max_length=255)
class Car(models.Model):
name = models.CharField(max_length=255)
from django.db import models
class Car(models.Model):
name = models.CharField(max_length=255)
class CarModel(models.Model):
name = models.CharField(max_length=255)
car = models.ForeignKey(Car, on_delete=models.CASCADE)
from django.db import models
class Car(models.Model):
name = models.CharField(max_length=255)
class Ceo(models.Model):
name = models.CharField(max_length=255, blank=True)
car = models.OneToOneField(Car, on_delete=models.CASCADE)
from polymorphic.models import PolymorphicModel
class Drive(PolymorphicModel):
name = models.CharField(max_length=255)
def __str__(self):
return self.name
class CarModel(models.Model):
name = models.CharField(max_length=255)
audio = models.ForeignKey(Audio, on_delete=models.CASCADE, related_name="carmodels", blank=True, null=True)
def __str__(self):
return self.name
from polymorphic.models import PolymorphicModel
class Audio(PolymorphicModel):
name = models.CharField(max_length=255)
def __str__(self):
return self.name
from django.db import models
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.fields import GenericRelation
from django.contrib.contenttypes.models import ContentType
class CarModel(models.Model):
name = models.CharField(max_length=255)
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
object_id = models.PositiveIntegerField()