Files
RasadDam_Backend/apps/livestock/models.py

88 lines
2.3 KiB
Python

from apps.core.models import BaseModel
from apps.herd import models as herd_models
from apps.tag import models as tag_models
from django.db import models
class LiveStockSpecies(BaseModel): # noqa
""" species of live stocks like Kurdi, Luri, etc """ # noqa
name = models.CharField(max_length=50)
def __str__(self):
return f'{self.name}'
def save(self, *args, **kwargs):
super(LiveStockSpecies, self).save(*args, **kwargs)
class LiveStockType(BaseModel): # noqa
""" types like sheep, cow, camel, etc """
name = models.CharField(max_length=50)
def __str__(self):
return f'{self.name}'
def save(self, *args, **kwargs):
super(LiveStockType, self).save(*args, **kwargs)
class LiveStockUseType(BaseModel):
""" use types like Beef, Milky, etc """
name = models.CharField(max_length=50)
def __str__(self):
return f'{self.name}'
def save(self, *args, **kwargs):
super(LiveStockUseType, self).save(*args, **kwargs)
class LiveStock(BaseModel):
herd = models.ForeignKey(
herd_models.Herd,
on_delete=models.CASCADE,
related_name="live_stock_herd",
null=True
)
tag = models.ForeignKey(
tag_models.Tag,
on_delete=models.CASCADE,
related_name='livestock_tag',
null=True
)
type = models.ForeignKey(
LiveStockType,
on_delete=models.CASCADE,
related_name='livestock_type',
null=True
)
use_type = models.ForeignKey(
LiveStockUseType,
on_delete=models.CASCADE,
related_name='livestock_use_type',
null=True
)
weight_types = (
('L', 'Light'),
('H', 'Heavy')
)
weight_type = models.CharField(max_length=1, choices=weight_types, default='L')
species = models.ForeignKey(
LiveStockSpecies,
on_delete=models.CASCADE,
related_name='livestock_species',
null=True,
)
birthdate = models.DateTimeField(null=True)
gender_type = (
(1, 'male'),
(2, 'female')
)
gender = models.IntegerField(choices=gender_type, default=1)
def __str__(self):
return f'{self.type.name}-{self.species.name}'
def save(self, *args, **kwargs):
super(LiveStock, self).save(*args, **kwargs)