Answer the question
In order to leave comments, you need to log in
Django. Why does the model change without slug and not with slugfield?
In general, the data did not change, I decided to remove the slug in the model and it all worked. Before that, when I changed something through the admin panel, and indeed through any tool, nothing changed, but for some reason, when I removed the slugfield, any field changes. Why is this happening?
Models (WAS)
from .for_slug import slugify as my_slugify
class Quiz(models.Model):
"""Quiz model"""
slug = models.SlugField('Url-адрес', max_length=50, blank=True)
.....
def save(self, *args, **kwargs):
"""Use the custom slugfiy (for_slug.py)"""
if not self.slug:
slug = my_slugify(self.title)
exists = Quiz.objects.filter(slug=slug).exists()
if exists:
slug += f'-{str(int(time()))}'
self.slug = slug
super().save(*args, **kwargs)
from django.template.defaultfilters import slugify as django_slugify
alphabet = {
'а': 'a', 'б': 'b', 'в': 'v', 'г': 'g', 'д': 'd', 'е': 'e',
'ё': 'yo', 'ж': 'zh', 'з': 'z', 'и': 'i', 'й': 'j', 'к': 'k',
'л': 'l', 'м': 'm', 'н': 'n', 'о': 'o', 'п': 'p', 'р': 'r',
'с': 's', 'т': 't', 'у': 'u', 'ф': 'f', 'х': 'kh', 'ц': 'ts',
'ч': 'ch', 'ш': 'sh', 'щ': 'shch', 'ы': 'i', 'э': 'e', 'ю': 'yu',
'я': 'ya'
}
def slugify(s):
return django_slugify(''.join(alphabet.get(w, w) for w in s.lower()))
Answer the question
In order to leave comments, you need to log in
The issue is resolved, all due to the fact that I wrote if not self.slug in the save method, I just had to remove this condition.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question