Skip to content

Commit

Permalink
Remove slug method and fix help texts
Browse files Browse the repository at this point in the history
  • Loading branch information
Floris272 committed Aug 8, 2024
1 parent 1c5d9d7 commit 191ab18
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 31 deletions.
16 changes: 0 additions & 16 deletions src/open_producten/producttypes/models/category.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()
4 changes: 2 additions & 2 deletions src/open_producten/producttypes/models/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 10 additions & 8 deletions src/open_producten/producttypes/models/producttype.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -99,15 +101,15 @@ 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(
Category,
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,
)

Expand Down
12 changes: 7 additions & 5 deletions src/open_producten/producttypes/models/question.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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

0 comments on commit 191ab18

Please sign in to comment.