From 191ab18db4546aadee9364bdab21ad1e7d8c4e7d Mon Sep 17 00:00:00 2001 From: Floris272 Date: Thu, 8 Aug 2024 12:00:45 +0200 Subject: [PATCH] Remove slug method and fix help texts --- .../producttypes/models/category.py | 16 ---------------- src/open_producten/producttypes/models/file.py | 4 ++-- .../producttypes/models/producttype.py | 18 ++++++++++-------- .../producttypes/models/question.py | 12 +++++++----- 4 files changed, 19 insertions(+), 31 deletions(-) diff --git a/src/open_producten/producttypes/models/category.py b/src/open_producten/producttypes/models/category.py index 7715b3c..be3e1a6 100644 --- a/src/open_producten/producttypes/models/category.py +++ b/src/open_producten/producttypes/models/category.py @@ -1,5 +1,4 @@ from django.db import models -from django.urls import reverse from django.utils.translation import gettext_lazy as _ from treebeard.exceptions import InvalidMoveToDescendant @@ -49,20 +48,5 @@ class Meta: def __str__(self): return self.name - def get_build_slug(self): - if self.is_root(): - build_slug = self.slug - else: - build_slug = "/".join( - list(self.get_ancestors().values_list("slug", flat=True)) - ) - build_slug += f"/{self.slug}" - return build_slug - - def get_absolute_url(self): - return reverse( - "products:category_detail", kwargs={"slug": self.get_build_slug()} - ) - def move(self, target, pos=None): return PublishedMoveHandler(self, target, pos).process() diff --git a/src/open_producten/producttypes/models/file.py b/src/open_producten/producttypes/models/file.py index fadf563..efdddb7 100644 --- a/src/open_producten/producttypes/models/file.py +++ b/src/open_producten/producttypes/models/file.py @@ -17,8 +17,8 @@ class File(BaseModel): file = models.FileField(verbose_name=_("File")) class Meta: - verbose_name = _("Product file") - verbose_name_plural = _("Product files") + verbose_name = _("Product type file") + verbose_name_plural = _("Product type files") def __str__(self): return self.file.name diff --git a/src/open_producten/producttypes/models/producttype.py b/src/open_producten/producttypes/models/producttype.py index d495b84..eccd2e1 100644 --- a/src/open_producten/producttypes/models/producttype.py +++ b/src/open_producten/producttypes/models/producttype.py @@ -16,25 +16,27 @@ class CategoryProductType(models.Model): """ category = models.ForeignKey(Category, on_delete=models.CASCADE) - product = models.ForeignKey("ProductType", on_delete=models.CASCADE) + product_type = models.ForeignKey("ProductType", on_delete=models.CASCADE) order_with_respect_to = "category" def get_product_name(self): - return self.product.name + return self.product_type.name get_product_name.short_description = _("Name") class ProductType(BasePublishableModel): name = models.CharField( - verbose_name=_("Name"), max_length=100, help_text=_("Name of the product") + verbose_name=_("Name"), max_length=100, help_text=_("Name of the product type") ) summary = models.TextField( verbose_name=_("Summary"), default="", max_length=300, - help_text=_("Short description of the product, limited to 300 characters."), + help_text=_( + "Short description of the product type, limited to 300 characters." + ), ) icon = models.ImageField( @@ -55,12 +57,12 @@ class ProductType(BasePublishableModel): verbose_name=_("Form link"), blank=True, default="", - help_text=_("Action link to request the product."), + help_text=_("Action link to request the product type."), ) content = models.TextField( verbose_name=_("Content"), - help_text=_("Product content with build-in WYSIWYG editor."), + help_text=_("Product type content with build-in WYSIWYG editor."), ) related_product_types = models.ManyToManyField( @@ -99,7 +101,7 @@ class ProductType(BasePublishableModel): verbose_name=_("Tags"), blank=True, related_name="product_types", - help_text=_("Tags which the product is linked to"), + help_text=_("Tags which the product type is linked to"), ) categories = models.ManyToManyField( @@ -107,7 +109,7 @@ class ProductType(BasePublishableModel): verbose_name=_("Categories"), blank=True, related_name="product_types", - help_text=_("Categories which the product is linked to"), + help_text=_("Categories which the product type is linked to"), through=CategoryProductType, ) diff --git a/src/open_producten/producttypes/models/question.py b/src/open_producten/producttypes/models/question.py index 4f39f5d..f67165d 100644 --- a/src/open_producten/producttypes/models/question.py +++ b/src/open_producten/producttypes/models/question.py @@ -16,7 +16,7 @@ class Question(BaseModel): blank=True, null=True, ) - product = models.ForeignKey( + product_type = models.ForeignKey( ProductType, verbose_name=_("Product type"), on_delete=models.CASCADE, @@ -33,13 +33,15 @@ class Meta: verbose_name_plural = _("Questions") def clean(self): - if self.category and self.product: + if self.category and self.product_type: raise ValidationError( - "A question cannot have both a category and a product" + "A question cannot have both a category and a product type" ) - if not self.category and not self.product: - raise ValidationError("A question must have either a category or a product") + if not self.category and not self.product_type: + raise ValidationError( + "A question must have either a category or a product type" + ) def __str__(self): return self.question