cms/cmsMain/models.py

73 lines
2.6 KiB
Python
Raw Permalink Normal View History

2024-08-11 22:39:47 +03:00
from django.db import models
2024-09-01 15:07:03 +03:00
from django.contrib.auth.models import User
2024-08-11 22:39:47 +03:00
# Create your models here.
class Page(models.Model):
2024-08-13 14:41:25 +03:00
title = models.CharField("Название",max_length=50)
2024-08-11 22:39:47 +03:00
content = models.TextField("Содержимое")
2024-08-13 14:41:25 +03:00
def __str__(self):
return self.title
2024-08-11 22:39:47 +03:00
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 = "Сайт"
2024-08-13 14:41:25 +03:00
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 = "Переменная"
2024-09-01 15:07:03 +03:00
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):
2024-09-07 18:59:47 +03:00
site = models.ForeignKey(Site,verbose_name="Сайт",on_delete=models.PROTECT)
2024-09-01 15:07:03 +03:00
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 = "Обращения"