Coverage for src/products/models/base.py: 96%

24 statements  

« prev     ^ index     » next       coverage.py v7.9.2, created at 2025-09-21 16:24 +0300

1from django.contrib.contenttypes.fields import GenericRelation 

2from django.db import models 

3 

4from src.products.models.inventory import Inventory 

5from src.products.models.review import Review 

6 

7 

8class BaseProduct(models.Model): 

9 class GenderChoices(models.TextChoices): 

10 MALE = "M", "Male" 

11 FEMALE = "F", "Female" 

12 

13 inventory = GenericRelation(Inventory) 

14 review = GenericRelation(Review) 

15 

16 class Meta: 

17 abstract = True 

18 

19 first_image = models.URLField( 

20 unique=True, 

21 ) 

22 

23 second_image = models.URLField( 

24 unique=True, 

25 ) 

26 

27 third_image = models.URLField( 

28 unique=True, 

29 ) 

30 

31 fourth_image = models.URLField( 

32 unique=True, 

33 ) 

34 

35 created_at = models.DateTimeField( 

36 auto_now_add=True, 

37 ) 

38 

39 collection = models.ForeignKey( 

40 to='products.Collection', 

41 on_delete=models.CASCADE, 

42 ) 

43 

44 color = models.ForeignKey( 

45 to='products.Color', 

46 on_delete=models.CASCADE, 

47 ) 

48 

49 metal = models.ForeignKey( 

50 to='products.Metal', 

51 on_delete=models.CASCADE, 

52 ) 

53 

54 stone = models.ForeignKey( 

55 to='products.Stone', 

56 on_delete=models.CASCADE, 

57 ) 

58 

59 target_gender = models.CharField( 

60 max_length=1, 

61 choices=GenderChoices.choices, 

62 default=GenderChoices.FEMALE, 

63 null=True, 

64 blank=True, 

65 ) 

66 

67 def __str__(self): 

68 return f'{self.collection} {self.__class__.__name__}'