Skip to content

Instantly share code, notes, and snippets.

@lgobatto
Created January 20, 2021 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lgobatto/7187033a642be06d99df1da5600f7633 to your computer and use it in GitHub Desktop.
Save lgobatto/7187033a642be06d99df1da5600f7633 to your computer and use it in GitHub Desktop.
from django.db import models
from django.core.validators import MaxValueValidator, MinValueValidator
from django.utils.translation import gettext_lazy as _
# Create your models here.
class CommonModel(models.Model):
name = models.CharField(max_length=128, unique=True)
created_at = models.DateTimeField(_('created date'), auto_now=True)
class Meta:
abstract = True
def __str__(self):
return self.name
class KingdomModel(CommonModel):
class Meta:
verbose_name = _("kingdom")
verbose_name_plural = _("kingdoms")
pass
class PhylumModel(CommonModel):
kingdon_model = models.ForeignKey(KingdomModel, on_delete=models.CASCADE)
class Meta:
verbose_name = _("phylum")
verbose_name_plural = _("phylums")
class ClassModel(CommonModel):
phylum_model = models.ForeignKey(PhylumModel, on_delete=models.CASCADE)
class Meta:
verbose_name = _("class")
verbose_name_plural = _("classes")
class OrderModel(CommonModel):
class_model = models.ForeignKey(ClassModel, on_delete=models.CASCADE)
class Meta:
verbose_name = _("order")
verbose_name_plural = _("orders")
class FamilyModel(CommonModel):
order_model = models.ForeignKey(OrderModel, on_delete=models.CASCADE)
class Meta:
verbose_name = _("family")
verbose_name_plural = _("families")
class GenusModel(CommonModel):
family_model = models.ForeignKey(FamilyModel, on_delete=models.CASCADE)
class Meta:
verbose_name = _("genus")
verbose_name_plural = _("genuses")
class SpeciesModel(CommonModel):
genus_model = models.ForeignKey(GenusModel, on_delete=models.CASCADE)
popular_name = models.CharField(max_length=128)
featured_image = models.ImageField(upload_to='species', null=True)
certificate_image = models.ImageField(upload_to='species', null=True)
average_lifetime = models.IntegerField(help_text=_("Lifespan in years"))
average_weight = models.IntegerField(help_text=_("Weight in grams"))
average_size = models.IntegerField(help_text=_("Size in centimeters"))
noise_level = models.IntegerField(
validators=[MaxValueValidator(10), MinValueValidator(0)])
talk_ability = models.IntegerField(
validators=[MaxValueValidator(10), MinValueValidator(0)])
docility_and_sociability = models.IntegerField(
validators=[MaxValueValidator(10), MinValueValidator(0)])
short_description = models.TextField(null=True, blank=True)
distribution = models.TextField(null=True, blank=True)
habitat = models.TextField(null=True, blank=True)
diet_and_foraging = models.TextField(null=True, blank=True)
breeding = models.TextField(null=True, blank=True)
conservation_status = models.TextField(null=True, blank=True)
class Meta:
verbose_name = _("specie")
verbose_name_plural = _("species")
class MutationModel(CommonModel):
species_model = models.ManyToManyField(SpeciesModel)
class Meta:
verbose_name = _("mutation")
verbose_name_plural = _("mutations")
class AnimalsModel(models.Model):
class GendersTextChoices(models.TextChoices):
MALE = 'M', _("Male")
FEMALE = 'F', _("Female")
created_at = models.DateTimeField(_('created date'), auto_now=True)
species_model = models.ForeignKey(SpeciesModel, on_delete=models.CASCADE)
individual_id = models.CharField(max_length=64)
birth_date = models.DateField()
gender = models.CharField(
max_length=1, choices=GendersTextChoices.choices, default=GendersTextChoices.MALE)
name = models.CharField(max_length=128, null=True, blank=True)
class Meta:
verbose_name = _("animal")
verbose_name_plural = _("animals")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment