Coverage for animals\models.py: 98%

42 statements  

« prev     ^ index     » next       coverage.py v7.8.2, created at 2025-06-07 22:09 +0200

1from decimal import Decimal 

2 

3from django.conf import settings 

4from django.db import models 

5from django.utils import timezone 

6 

7 

8class Animal(models.Model): 

9 GENDER_CHOICES = [ 

10 ("male", "Macho"), 

11 ("female", "Hembra"), 

12 ] 

13 

14 SIZE_CHOICES = [ 

15 ("small", "Pequeño"), 

16 ("medium", "Mediano"), 

17 ("large", "Grande"), 

18 ] 

19 

20 ACTIVITY_CHOICES = [ 

21 ("low", "Baja"), 

22 ("medium", "Media"), 

23 ("high", "Alta"), 

24 ] 

25 

26 name = models.CharField(max_length=100, default="Nombre del animal") 

27 age = models.CharField(max_length=50, default="0 años") 

28 gender = models.CharField(max_length=10, choices=GENDER_CHOICES, default="male") 

29 size = models.CharField(max_length=10, choices=SIZE_CHOICES, default="medium") 

30 activity = models.CharField(max_length=10, choices=ACTIVITY_CHOICES, default="low") 

31 city = models.CharField(max_length=100, default="Ciudad desconocida") 

32 biography = models.TextField(default="Biografía no disponible") 

33 

34 species = models.CharField(max_length=50, default="Especie desconocida") 

35 breed = models.CharField( 

36 max_length=100, blank=True, null=True, default="Raza desconocida" 

37 ) 

38 

39 weight = models.DecimalField( 

40 max_digits=5, decimal_places=2, null=True, blank=True, default=Decimal("0.0") 

41 ) 

42 characteristics = models.JSONField(blank=True, null=True, default=dict) 

43 

44 owner = models.ForeignKey( 

45 settings.AUTH_USER_MODEL, 

46 on_delete=models.CASCADE, 

47 related_name="animals", 

48 null=True, 

49 blank=True, 

50 help_text="Usuario/protectora que creó este registro", 

51 ) 

52 adopter = models.ForeignKey( 

53 settings.AUTH_USER_MODEL, 

54 on_delete=models.SET_NULL, 

55 related_name="adopted_animals", 

56 null=True, 

57 blank=True, 

58 help_text="Usuario que ha adoptado este animal", 

59 ) 

60 since = models.DateField(default=timezone.localdate) 

61 

62 vaccinated = models.BooleanField(default=False) 

63 sterilized = models.BooleanField(default=False) 

64 microchipped = models.BooleanField(default=False) 

65 dewormed = models.BooleanField(default=False) 

66 

67 image = models.ImageField( 

68 upload_to="animal_images/", default="animal_images/default_image.jpg" 

69 ) 

70 extra_images = models.JSONField(blank=True, null=True, default=dict) 

71 

72 latitude = models.FloatField(null=True, blank=True) 

73 longitude = models.FloatField(null=True, blank=True) 

74 

75 created_at = models.DateTimeField(auto_now_add=True) 

76 updated_at = models.DateTimeField(auto_now=True) 

77 

78 def __str__(self): 

79 return self.name 

80 

81 

82class AdoptionRequest(models.Model): 

83 user = models.ForeignKey( 

84 settings.AUTH_USER_MODEL, 

85 related_name="adoption_requests", 

86 on_delete=models.CASCADE, 

87 ) 

88 animal = models.ForeignKey( 

89 Animal, related_name="adoption_requests", on_delete=models.CASCADE 

90 ) 

91 created_at = models.DateTimeField(auto_now_add=True) 

92 

93 # Nuevo campo para guardar el JSON del formulario 

94 form_data = models.JSONField( 

95 blank=True, default=dict, help_text="Datos completos del formulario de adopción" 

96 ) 

97 

98 class Meta: 

99 unique_together = ("user", "animal") 

100 ordering = ("-created_at",)