diff --git a/shopelectro/models.py b/shopelectro/models.py index 2cb05e2f..4c43ee8c 100644 --- a/shopelectro/models.py +++ b/shopelectro/models.py @@ -1,11 +1,17 @@ -from typing import Optional +import random +import string +from itertools import chain, groupby +from operator import attrgetter +import typing from uuid import uuid4 from django.conf import settings from django.db import models from django.urls import reverse +from django.utils.text import slugify from django.utils.translation import ugettext_lazy as _ from mptt.querysets import TreeQuerySet +from unidecode import unidecode from catalog.models import ( AbstractCategory, @@ -19,6 +25,13 @@ from pages.models import CustomPage, ModelPage, Page, SyncPageMixin, PageManager +def randomize_slug(slug: str) -> str: + slug_hash = ''.join( + random.choices(string.ascii_lowercase, k=settings.SLUG_HASH_SIZE) + ) + return f'{slug}_{slug_hash}' + + class SECategoryQuerySet(TreeQuerySet): def get_categories_tree_with_pictures(self) -> 'SECategoryQuerySet': categories_with_pictures = (