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=10, 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.DecimalField(max_digits=22, decimal_places=16, null=True) longitude = models.DecimalField(max_digits=22, decimal_places=16, null=True) 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) 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=20, null=True) birthdate = models.DateTimeField(null=True) nationality = models.CharField(max_length=20, 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) def __str__(self): return f'rancher: {self.first_name} {self.last_name}' def save(self, *args, **kwargs): return super(Rancher, self).save(*args, **kwargs)