24 lines
734 B
Python
24 lines
734 B
Python
from django.db import models
|
|
from django_ckeditor_5.fields import CKEditor5Field
|
|
from pytils.translit import slugify
|
|
|
|
|
|
class BaseContentItem(models.Model):
|
|
name = models.CharField(max_length=255)
|
|
description = CKEditor5Field('Text', config_name='default')
|
|
created_at = models.DateTimeField(blank=True, null=True)
|
|
updated_at = models.DateTimeField(auto_now=True)
|
|
slug = models.SlugField(unique=True, blank=True, null=True, max_length=255)
|
|
|
|
def save(self, *args, **kwargs):
|
|
if not self.slug:
|
|
self.slug = slugify(self.name)
|
|
return super().save(*args, **kwargs)
|
|
|
|
def __str__(self):
|
|
return self.name
|
|
|
|
class Meta:
|
|
abstract = True
|
|
ordering = ['created_at']
|