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

18 statements  

« prev     ^ index     » next       coverage.py v7.9.2, created at 2025-08-04 12:59 +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 inventory = GenericRelation(Inventory) 

10 review = GenericRelation(Review) 

11 

12 class Meta: 

13 abstract = True 

14 

15 first_image = models.URLField( 

16 unique=True, 

17 ) 

18 

19 second_image = models.URLField( 

20 unique=True, 

21 ) 

22 

23 created_at = models.DateTimeField( 

24 auto_now_add=True, 

25 ) 

26 

27 collection = models.ForeignKey( 

28 to='products.Collection', 

29 on_delete=models.CASCADE, 

30 ) 

31 

32 color = models.ForeignKey( 

33 to='products.Color', 

34 on_delete=models.CASCADE, 

35 ) 

36 

37 metal = models.ForeignKey( 

38 to='products.Metal', 

39 on_delete=models.CASCADE, 

40 ) 

41 

42 stone = models.ForeignKey( 

43 to='products.Stone', 

44 on_delete=models.CASCADE, 

45 ) 

46 

47 def __str__(self): 

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