Files
RasadDam_Backend/apps/livestock/models.py

124 lines
3.3 KiB
Python

from django.db import models
from apps.core.models import BaseModel
from apps.herd import models as herd_models
from apps.tag import models as tag_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, null=True)
en_name = models.CharField(max_length=50, null=True)
weight_types = (
('L', 'Light'),
('H', 'Heavy')
)
weight_type = models.CharField(
choices=weight_types,
max_length=50,
null=True
)
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, null=True)
en_name = models.CharField(max_length=50, null=True)
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",
db_index=True,
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)
archive = models.BooleanField(default=False)
def __str__(self):
return f"{self.type.name if self.type else ''}-{self.species.name if self.species else ''}"
def save(self, *args, **kwargs):
return super(LiveStock, self).save(*args, **kwargs)
class TemporaryLiveStock(BaseModel):
rancher = models.ForeignKey(
herd_models.Rancher,
on_delete=models.CASCADE,
related_name='temporary_stocks',
null=True
)
livestock_type = models.ForeignKey(
LiveStockType,
on_delete=models.CASCADE,
related_name='temporary_stocks',
null=True
)
count = models.PositiveBigIntegerField(default=0)
def __str__(self):
return f'temporary: {self.id} - rancher: {self.rancher.national_code}'
def save(self, *args, **kwargs):
return super(TemporaryLiveStock, self).save(*args, **kwargs)