diff options
Diffstat (limited to 'servo/models/product.py')
-rw-r--r-- | servo/models/product.py | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/servo/models/product.py b/servo/models/product.py index 189ca8a..7ec2b30 100644 --- a/servo/models/product.py +++ b/servo/models/product.py @@ -10,7 +10,6 @@ from django.core.files import File from django.core.cache import cache from decimal import Decimal, ROUND_CEILING from django.urls import reverse -from django.contrib.sites.models import Site from django.contrib.contenttypes.fields import GenericRelation @@ -547,11 +546,7 @@ class Product(AbstractBaseProduct): class ProductCategory(MPTTModel): - site = models.ForeignKey( - Site, - editable=False, - default=defaults.site_id - ) + title = models.CharField( max_length=255, unique=True, @@ -562,7 +557,8 @@ class ProductCategory(MPTTModel): 'self', null=True, blank=True, - related_name='children' + related_name='children', + on_delete=models.CASCADE, ) objects = TreeManager() @@ -596,15 +592,14 @@ class ProductCategory(MPTTModel): app_label = "servo" get_latest_by = "id" ordering = ("-title",) - unique_together = ("title", "site",) class Inventory(models.Model): """ Inventory tracks how much of Product X is in Location Y """ - product = models.ForeignKey(Product) - location = models.ForeignKey(Location) + product = models.ForeignKey(Product, on_delete=models.CASCADE) + location = models.ForeignKey(Location, on_delete=models.CASCADE) amount_minimum = models.PositiveIntegerField( default=0, @@ -630,8 +625,9 @@ class Inventory(models.Model): if new_location == self.location: raise ValueError(_('Cannot move products to the same location')) - target, created = Inventory.objects.get_or_create(location=new_location, - product=self.product) + target, created = Inventory.objects.get_or_create( + location=new_location, + product=self.product) self.amount_stocked = self.amount_stocked - amount self.save() target.amount_stocked = target.amount_stocked + amount |