Skip to content

Commit 4532ea3

Browse files
committed
first commit
0 parents  commit 4532ea3

File tree

1,476 files changed

+76819
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,476 files changed

+76819
-0
lines changed

.gitignore

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
venv
2+
3+
local_settings.py
4+
prode_settings.py
5+
6+
**/migrations/**
7+
!**/migrations
8+
!**/migrations/__init__.py
9+
__pycache__/
10+
*/__pycache__/
11+
12+
*.py[cod]
13+
.pyc
14+
*.pyc
15+
!media
16+
media/*
17+
log/debug.log

.idea/.gitignore

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/dataSources.xml

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/django_book.iml

+31
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/profiles_settings.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

books/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import books.apps
2+
3+
default_app_config = 'books.apps.BooksConfig'

books/admin.py

+194
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
from django import forms
2+
from django.contrib import admin
3+
4+
from django.utils.safestring import mark_safe
5+
6+
7+
from .models import Category, Genre, Book, BookShots, Avtor, RatingStar, Rating, Reviews, Publishing, Country
8+
9+
10+
from ckeditor_uploader.widgets import CKEditorUploadingWidget
11+
12+
13+
14+
class BookAdminForm(forms.ModelForm):
15+
description = forms.CharField(label="Описание", widget=CKEditorUploadingWidget())
16+
class Meta:
17+
model = Book
18+
fields = '__all__'
19+
20+
21+
22+
23+
24+
25+
@admin.register(Category)
26+
class CategoryAdmin(admin.ModelAdmin):
27+
"""Категории"""
28+
list_display = ("id", "name", "url")
29+
list_display_links = ("name", )
30+
31+
32+
33+
class ReviewInline(admin.TabularInline):
34+
"""Отзывы на странице"""
35+
model = Reviews
36+
extra = 0
37+
readonly_fields = ("name", "email",)
38+
39+
40+
41+
@admin.register(Book)
42+
class BookAdmin(admin.ModelAdmin):
43+
"""Книги"""
44+
list_display = ("title", "category", "url", "draft", )
45+
list_filter = ("category", "draft", "year", "avtors", )
46+
search_fields = ("title", )
47+
inlines = [ReviewInline]
48+
save_on_top = True
49+
save_as = True
50+
actions = ["publish", "unpublishg"]
51+
52+
list_editable = ("draft", )
53+
form = BookAdminForm
54+
readonly_fields = ("get_image", )
55+
fieldsets = (
56+
(None, {
57+
"fields": (("title", ), )
58+
}),
59+
(None, {
60+
"fields": (("description", ),)
61+
}),
62+
(None, {
63+
"fields": (("poster", "get_image", "ebook"),)
64+
}),
65+
(None, {
66+
"fields": (("countrys", "language", ),)
67+
}),
68+
(None, {
69+
"fields": (("year", "world_publishing",),)
70+
}),
71+
(None, {
72+
"fields": (("isbn", "pages",),)
73+
}),
74+
(None, {
75+
"fields": (("avtors", "publishings", "genres", "category", ),)
76+
}),
77+
("Options", {
78+
"fields": (("url", "draft",),)
79+
}),
80+
)
81+
def get_image(self, obj):
82+
return mark_safe(f'<img src={obj.poster.url} width="100" height="100"')
83+
84+
def publish(self, request, queryset):
85+
"""Опубликовать"""
86+
row_update = queryset.update(draft=False)
87+
if row_update == 1:
88+
message_bit = '1 запись была обновлена'
89+
else:
90+
message_bit = f"{row_update} записей обновлены"
91+
self.message_user(request, f"{message_bit}")
92+
93+
def unpublishg(self, request, queryset):
94+
"""Снять с публикации"""
95+
row_update = queryset.update(draft=True)
96+
if row_update == 1:
97+
message_bit = '1 запись была обновлена'
98+
else:
99+
message_bit = f"{row_update} записей обновлены"
100+
self.message_user(request, f"{message_bit}")
101+
102+
103+
104+
publish.short_description = "Опубликовать"
105+
publish.allowed_permissions = ('change',)
106+
107+
unpublishg.short_description = "Снять с публикации"
108+
unpublishg.allowed_permissions = ('change',)
109+
110+
get_image.short_description = "Постер"
111+
112+
113+
114+
115+
116+
@admin.register(Reviews)
117+
class ReviewAdmin(admin.ModelAdmin):
118+
"""Отзывы"""
119+
list_display = ("name", "email", "parent", "book", "id")
120+
readonly_fields = ("name", "email", )
121+
122+
123+
124+
125+
@admin.register(Genre)
126+
class GenreAdmin(admin.ModelAdmin):
127+
"""Жанры"""
128+
list_display = ("name", "url")
129+
130+
131+
132+
@admin.register(Avtor)
133+
class ActorAdmin(admin.ModelAdmin):
134+
"""Авторы"""
135+
list_display = ("name", "age", "get_image", )
136+
readonly_fields = ("get_image", )
137+
search_fields = ("name", )
138+
139+
def get_image(self, obj):
140+
return mark_safe(f'<img src={obj.image.url} width="50" height="60"')
141+
142+
get_image.short_description = "Изображение"
143+
144+
145+
146+
147+
@admin.register(Rating)
148+
class RatingAdmin(admin.ModelAdmin):
149+
"""Рейтинг"""
150+
list_display = ("star", "ip")
151+
152+
153+
154+
@admin.register(BookShots)
155+
class BookShotsAdmin(admin.ModelAdmin):
156+
"""Кадры из книги"""
157+
list_display = ("title", "book")
158+
159+
160+
161+
@admin.register(Publishing)
162+
class PublishingAdmin(admin.ModelAdmin):
163+
list_display = ("name", "image", )
164+
165+
166+
167+
@admin.register(Country)
168+
class CountryAdmin(admin.ModelAdmin):
169+
list_display = ("name", "image", )
170+
search_fields = ("name", )
171+
172+
173+
174+
175+
176+
177+
178+
179+
# admin.site.register(Category, CategoryAdmin)
180+
181+
#admin.site.register(Genre)
182+
# admin.site.register(Book)
183+
#admin.site.register(BookShots)
184+
#admin.site.register(Avtor)
185+
#admin.site.register(Rating)
186+
admin.site.register(RatingStar)
187+
#admin.site.register(Reviews)
188+
#admin.site.register(Publishing)
189+
#admin.site.register(Country)
190+
191+
admin.site.site_title = "Digital Library"
192+
admin.site.site_header = "Digital Library"
193+
194+

books/apps.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from django.apps import AppConfig
2+
3+
4+
class BooksConfig(AppConfig):
5+
default_auto_field = 'django.db.models.BigAutoField'
6+
name = 'books'
7+
verbose_name = "Книги"

books/forms.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from django import forms
2+
3+
from .models import Reviews
4+
5+
class ReviewForm(forms.ModelForm):
6+
"""Form review"""
7+
class Meta:
8+
model = Reviews
9+
fields = ("name", "email", "text")

books/migrations/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)