cms/cmsMain/models.py
2024-09-07 18:59:47 +03:00

73 lines
No EOL
2.6 KiB
Python

from django.db import models
from django.contrib.auth.models import User
# Create your models here.
class Page(models.Model):
title = models.CharField("Название",max_length=50)
content = models.TextField("Содержимое")
def __str__(self):
return self.title
class Meta:
verbose_name = "Страница"
verbose_name_plural = "Страницы"
class Site(models.Model):
domain = models.CharField("Домен",max_length=50)
base_page = models.ForeignKey(Page,on_delete=models.PROTECT,verbose_name="Базовая страница")
def __str__(self) -> str:
return self.domain
class Meta:
verbose_name = "Сайт"
verbose_name_plural = "Сайты"
class Url(models.Model):
site = models.ForeignKey(Site,on_delete=models.PROTECT,verbose_name="Сайт")
path = models.CharField("Путь",max_length=50)
page = models.ForeignKey(Page,on_delete=models.PROTECT,verbose_name="Страница")
def __str__(self):
return f"{self.site.domain}/{self.path}"
class Meta:
verbose_name="Ссылка"
verbose_name_plural="Ссылки"
class Variable(models.Model):
name = models.CharField("Имя",max_length=50)
value = models.TextField("Значение")
def __str__(self):
return self.name
class Meta:
verbose_name = "Переменная"
verbose_name_plural = "Переменные"
class File(models.Model):
name = models.CharField("Имя",max_length=50)
value = models.FileField("Значение",upload_to="files")
def __str__(self):
return self.name
class Meta:
verbose_name = "Файл"
verbose_name_plural = "Файлы"
class Post(models.Model):
site = models.ForeignKey(Site,verbose_name="Сайт",on_delete=models.PROTECT)
url = models.CharField("Ссылка",help_text="например: my-first-test-post",max_length=100)
title = models.CharField("Название",max_length=100)
author = models.ForeignKey(User,editable=False,verbose_name="Автор",on_delete=models.PROTECT)
content = models.TextField("Содержимое")
created_at = models.DateTimeField(auto_now_add=True)
def __str__(self):
return f"{self.title} by {self.author.username}"
class Meta:
verbose_name = "Пост"
verbose_name_plural = "Посты"
class Feedback(models.Model):
email = models.EmailField("Почта")
name = models.CharField("Имя",max_length=50)
message = models.TextField("Сообщение")
def __str__(self):
return f"{self.name} | {self.name}"
class Meta:
verbose_name = "Обращение"
verbose_name_plural = "Обращения"