Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 146 additions & 1 deletion apps/books/models.py
Original file line number Diff line number Diff line change
@@ -1 +1,146 @@
# Create your models here.
from django.db import models
from django.contrib.auth import get_user_model
from django_extensions.db.models import TimeStampedModel

User = get_user_model()


class Publisher(models.Model):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TimeStampedModel

name = models.CharField(
"Название издательства",
max_length=255,
)
website = models.URLField(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Отформатировать порядок передачи аргументов

"Сайт издательства",
max_length=255,
blank=True,
)

class Meta:
verbose_name = "Издательство"
verbose_name_plural = "Издательства"

def __str__(self):
return self.name


class Author(models.Model):
first_name = models.CharField(
"Имя автора",
max_length=100,
)
last_name = models.CharField(
"Фамилия автора",
max_length=100,
)
bio = models.TextField(
"Биография",
blank=True,
)

class Meta:
verbose_name = "Автор"
verbose_name_plural = "Авторы"

def __str__(self):
return f"{self.first_name} {self.last_name}"


class Tag(models.Model):
name = models.CharField(
"Название тега",
max_length=100,
unique=True,
)
slug = models.SlugField(
"URL-имя",
max_length=100,
unique=True,
)
color = models.CharField(
"Цвет",
max_length=20,
)

class Meta:
verbose_name = "Тег"
verbose_name_plural = "Теги"

def __str__(self):
return self.name


class Book(TimeStampedModel):
title = models.CharField(
"Название книги",
max_length=255,
)
description = models.TextField(
"Описание книги",
)
published_at = models.DateField(
"Дата публикации",
)
isbn_code = models.CharField(
"ISBN",
max_length=20,
unique=True,
)
total_pages = models.IntegerField(
"Количество страниц",
)
cover_image = models.URLField(
"Обложка книги",
max_length=255,
)
language = models.CharField(
"Язык",
max_length=50,
)

author = models.ManyToManyField(
Author,
verbose_name="Авторы",
related_name="books",
)
publisher = models.ForeignKey(
Publisher,
verbose_name="Издательство",
on_delete=models.CASCADE,
related_name="books",
)
tags = models.ManyToManyField(
Tag,
verbose_name="Теги",
related_name="books",
)

class Meta:
verbose_name = "Книга"
verbose_name_plural = "Книги"

def __str__(self):
return self.title


class Comment(TimeStampedModel):
text = models.TextField(
"Комментарий",
)

user = models.ForeignKey(
User,
verbose_name="Пользователь",
on_delete=models.CASCADE,
related_name="comments",
)
book = models.ForeignKey(
Book,
verbose_name="Книга",
on_delete=models.CASCADE,
related_name="comments",
)

class Meta:
verbose_name = "Комментарий"
verbose_name_plural = "Комментарии"
7 changes: 1 addition & 6 deletions config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/

Expand All @@ -27,7 +26,6 @@

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
Expand All @@ -38,6 +36,7 @@
"django.contrib.messages",
"django.contrib.staticfiles",
"apps.books.apps.BooksConfig",
"django_extensions",
]

MIDDLEWARE = [
Expand Down Expand Up @@ -69,7 +68,6 @@

WSGI_APPLICATION = "config.wsgi.application"


# Database
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases

Expand All @@ -80,7 +78,6 @@
}
}


# Password validation
# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators

Expand All @@ -99,7 +96,6 @@
},
]


# Internationalization
# https://docs.djangoproject.com/en/5.2/topics/i18n/
LANGUAGE_CODE = "en"
Expand All @@ -111,7 +107,6 @@
USE_I18N = True
USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.2/howto/static-files/

Expand Down
Binary file modified requirements.txt
Binary file not shown.