first base of project-changed apps: Herd-livestock-tag-log-elasticsearch-
This commit is contained in:
@@ -4,6 +4,39 @@ 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,
|
||||
@@ -17,15 +50,29 @@ class LiveStock(BaseModel):
|
||||
related_name='livestock_tag',
|
||||
null=True
|
||||
)
|
||||
types = (
|
||||
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')
|
||||
)
|
||||
type = models.CharField(max_length=1, choices=types)
|
||||
species_type = (
|
||||
()
|
||||
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,
|
||||
)
|
||||
species = models.CharField(max_length=1, choices=species_type)
|
||||
birthdate = models.DateTimeField(null=True)
|
||||
gender_type = (
|
||||
(1, 'male'),
|
||||
@@ -34,7 +81,7 @@ class LiveStock(BaseModel):
|
||||
gender = models.IntegerField(choices=gender_type, default=1)
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.get_species_display()}-{self.get_type_display()}'
|
||||
return f'{self.type.name}-{self.species.name}'
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
super(LiveStock, self).save(*args, **kwargs)
|
||||
|
||||
Reference in New Issue
Block a user