feat: added seo template and prioduct.slug

This commit is contained in:
2024-11-22 21:40:27 +01:00
parent 2d7119c6c1
commit b057b70a31
13 changed files with 644 additions and 33 deletions
+12 -2
View File
@@ -3,7 +3,7 @@ from uuid import uuid4
from django.db import models
from django.utils import timezone
from django.utils.text import gettext_lazy as _
from django.utils.text import gettext_lazy as _, slugify
class TimestampedModel(models.Model):
@@ -70,10 +70,20 @@ class Product(TimestampedModel):
on_delete=models.SET_NULL,
verbose_name=_("marca"),
)
slug = models.SlugField(default="", blank=True, null=True, max_length=128, verbose_name=_('Slug'))
def __str__(self):
return self.name
def save(
self,
*args,
**kwargs,
):
if not self.pk:
self.slug = slugify(self.name)[:128]
super().save(*args, **kwargs)
@property
def price(self):
return self.prices.filter(current=True).first()
@@ -81,7 +91,7 @@ class Product(TimestampedModel):
class Meta:
verbose_name = _("producto")
verbose_name_plural = _("productos")
ordering = ("-id",)
ordering = ("id",)
class ProductPrice(TimestampedModel):