140 lines
4.3 KiB
Python
140 lines
4.3 KiB
Python
from apps.core.models import BaseModel
|
|
from apps.authentication import models as auth_models
|
|
from django.db import models
|
|
|
|
|
|
class Herd(BaseModel):
|
|
owner = models.ForeignKey(
|
|
auth_models.User,
|
|
on_delete=models.CASCADE,
|
|
related_name='herd',
|
|
null=True
|
|
)
|
|
rancher = models.ForeignKey(
|
|
'Rancher',
|
|
on_delete=models.CASCADE,
|
|
related_name='herd',
|
|
null=True
|
|
)
|
|
cooperative = models.ForeignKey(
|
|
auth_models.Organization,
|
|
on_delete=models.CASCADE,
|
|
related_name='herd',
|
|
null=True
|
|
)
|
|
name = models.CharField(max_length=50)
|
|
photo = models.CharField(max_length=50, null=True)
|
|
code = models.CharField(max_length=20)
|
|
heavy_livestock_number = models.BigIntegerField(default=0)
|
|
light_livestock_number = models.BigIntegerField(default=0)
|
|
heavy_livestock_quota = models.BigIntegerField(default=0)
|
|
light_livestock_quota = models.BigIntegerField(default=0)
|
|
province = models.ForeignKey(
|
|
auth_models.Province,
|
|
on_delete=models.CASCADE,
|
|
related_name='herd_province',
|
|
null=True
|
|
)
|
|
city = models.ForeignKey(
|
|
auth_models.City,
|
|
on_delete=models.CASCADE,
|
|
related_name='herd_city',
|
|
null=True
|
|
)
|
|
postal = models.CharField(
|
|
max_length=20,
|
|
help_text="herd postal code", null=True
|
|
)
|
|
institution = models.CharField(
|
|
max_length=20,
|
|
help_text="herd institution code", null=True
|
|
)
|
|
epidemiologic = models.CharField(max_length=18, null=True) # noqa
|
|
contractor = models.ForeignKey(
|
|
auth_models.Organization,
|
|
on_delete=models.CASCADE,
|
|
related_name="herd_contractor",
|
|
null=True
|
|
)
|
|
latitude = models.FloatField(default=0)
|
|
longitude = models.FloatField(default=0)
|
|
unit_unique_id = models.CharField(max_length=20, null=True)
|
|
activity_types = (
|
|
("I", "Industrial"),
|
|
("V", "Village"),
|
|
("N", "Nomadic")
|
|
)
|
|
activity = models.CharField(
|
|
choices=activity_types,
|
|
max_length=1,
|
|
null=True
|
|
)
|
|
activity_state = models.BooleanField(default=False)
|
|
operating_license_state = models.BooleanField(default=False)
|
|
capacity = models.IntegerField(default=0)
|
|
|
|
def __str__(self):
|
|
return f'{self.name}-{self.code}'
|
|
|
|
def save(self, *args, **kwargs):
|
|
super(Herd, self).save(*args, **kwargs)
|
|
|
|
|
|
class Rancher(BaseModel):
|
|
ranching_farm = models.CharField(max_length=150, null=True)
|
|
union_name = models.CharField(max_length=50, null=True)
|
|
union_code = models.CharField(max_length=50, null=True)
|
|
activity_types = (
|
|
("I", "Industrial"),
|
|
("V", "Village"),
|
|
("N", "Nomadic")
|
|
)
|
|
activity = models.CharField(
|
|
choices=activity_types,
|
|
max_length=1,
|
|
null=True
|
|
)
|
|
rancher_types = (
|
|
('N', 'Natural'),
|
|
('L', 'Legal')
|
|
)
|
|
rancher_type = models.CharField(
|
|
max_length=1,
|
|
choices=rancher_types,
|
|
default='N',
|
|
help_text="N is natural & L is legal"
|
|
)
|
|
heavy_livestock_number = models.BigIntegerField(default=0)
|
|
light_livestock_number = models.BigIntegerField(default=0)
|
|
herd_code = models.CharField(max_length=100, null=True)
|
|
first_name = models.CharField(max_length=150, null=True)
|
|
last_name = models.CharField(max_length=150, null=True)
|
|
mobile = models.CharField(max_length=25, null=True)
|
|
national_code = models.CharField(max_length=50, null=True)
|
|
birthdate = models.DateTimeField(null=True)
|
|
nationality = models.CharField(max_length=50, null=True)
|
|
address = models.TextField(blank=True)
|
|
province = models.ForeignKey(
|
|
auth_models.Province,
|
|
on_delete=models.CASCADE,
|
|
related_name='ranchers',
|
|
null=True
|
|
)
|
|
city = models.ForeignKey(
|
|
auth_models.City,
|
|
on_delete=models.CASCADE,
|
|
related_name='ranchers',
|
|
null=True
|
|
)
|
|
without_herd = models.BooleanField(default=False)
|
|
ignore_purchase_limit = models.BooleanField(
|
|
default=False, help_text="if its true rancher has not buy limitations"
|
|
)
|
|
|
|
def __str__(self):
|
|
return f'rancher: {self.first_name} {self.last_name}'
|
|
|
|
def save(self, *args, **kwargs):
|
|
return super(Rancher, self).save(*args, **kwargs)
|
|
|