-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add models #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: add models #19
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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): | ||
| name = models.CharField( | ||
| "Название издательства", | ||
| max_length=255, | ||
| ) | ||
| website = models.URLField( | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 = "Комментарии" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
django-extensions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TimeStampedModel