Browse Source

library collections api added for admin panel

master
Mohsen Taba 3 weeks ago
parent
commit
a269e61d80
  1. 33
      apps/library/migrations/0004_alter_author_slug_alter_book_slug_and_more.py
  2. 8
      apps/library/models.py
  3. 9
      apps/library/serializers_admin.py

33
apps/library/migrations/0004_alter_author_slug_alter_book_slug_and_more.py

@ -0,0 +1,33 @@
# Generated by Django 5.2.12 on 2026-07-01 15:51
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('library', '0003_alter_book_author'),
]
operations = [
migrations.AlterField(
model_name='author',
name='slug',
field=models.SlugField(blank=True, max_length=255, null=True, unique=True),
),
migrations.AlterField(
model_name='book',
name='slug',
field=models.SlugField(blank=True, max_length=255, null=True, unique=True),
),
migrations.AlterField(
model_name='bookcollection',
name='slug',
field=models.SlugField(blank=True, max_length=255, null=True, unique=True),
),
migrations.AlterField(
model_name='category',
name='slug',
field=models.SlugField(blank=True, max_length=255, null=True, unique=True),
),
]

8
apps/library/models.py

@ -17,7 +17,7 @@ class BookCollection(models.Model):
# BOTTOM = 'bottom', _('Bottom Section') # BOTTOM = 'bottom', _('Bottom Section')
title = models.CharField(max_length=255) title = models.CharField(max_length=255)
slug = models.SlugField(max_length=255, unique=True)
slug = models.SlugField(max_length=255, unique=True, blank=True, null=True)
summary = models.CharField(max_length=512, null=True, blank=True, help_text=_('could be null')) summary = models.CharField(max_length=512, null=True, blank=True, help_text=_('could be null'))
pin_top = models.BooleanField(_('pin top'), default=True) pin_top = models.BooleanField(_('pin top'), default=True)
display_position = models.CharField( display_position = models.CharField(
@ -68,7 +68,7 @@ class MiddleBookCollection(BookCollection):
class Category(models.Model): class Category(models.Model):
title = models.CharField(max_length=255) title = models.CharField(max_length=255)
slug = models.SlugField(max_length=255, unique=True)
slug = models.SlugField(max_length=255, unique=True, blank=True, null=True)
status = models.BooleanField(default=True, verbose_name=_('status')) status = models.BooleanField(default=True, verbose_name=_('status'))
# books = models.ManyToManyField('library.Book', related_name='related_categories_books',through="library.Book_categories" ,verbose_name=_('Books'), blank=True) # books = models.ManyToManyField('library.Book', related_name='related_categories_books',through="library.Book_categories" ,verbose_name=_('Books'), blank=True)
@ -95,7 +95,7 @@ class Category(models.Model):
class Author(models.Model): class Author(models.Model):
full_name = models.CharField(max_length=255, verbose_name=_('Full Name')) full_name = models.CharField(max_length=255, verbose_name=_('Full Name'))
slug = models.SlugField(max_length=255, unique=True)
slug = models.SlugField(max_length=255, unique=True, blank=True, null=True)
thumbnail = models.ImageField( thumbnail = models.ImageField(
upload_to='author_thumbnails/', upload_to='author_thumbnails/',
null=True, null=True,
@ -133,7 +133,7 @@ class Book(models.Model):
docx = 'docx', 'Docx' docx = 'docx', 'Docx'
title = models.CharField(max_length=255) title = models.CharField(max_length=255)
slug = models.SlugField(max_length=255, unique=True)
slug = models.SlugField(max_length=255, unique=True, blank=True, null=True)
slogan = models.CharField(max_length=300, blank=True, null=True) slogan = models.CharField(max_length=300, blank=True, null=True)
summary_title = models.CharField(max_length=512, null=True, blank=True, help_text=_('Summary Title')) summary_title = models.CharField(max_length=512, null=True, blank=True, help_text=_('Summary Title'))

9
apps/library/serializers_admin.py

@ -137,6 +137,8 @@ class AdminBookDetailSerializer(serializers.ModelSerializer):
required=False required=False
) )
bookmark_count = serializers.SerializerMethodField()
class Meta: class Meta:
model = Book model = Book
fields = [ fields = [
@ -162,6 +164,7 @@ class AdminBookDetailSerializer(serializers.ModelSerializer):
"pin", "pin",
"view_count", "view_count",
"download_count", "download_count",
"bookmark_count",
"file_type", "file_type",
"book_file", "book_file",
"created_at", "created_at",
@ -173,7 +176,11 @@ class AdminBookDetailSerializer(serializers.ModelSerializer):
"remove_thumbnail", "remove_thumbnail",
"remove_book_file", "remove_book_file",
] ]
read_only_fields = ["id", "view_count", "download_count", "created_at", "updated_at"]
read_only_fields = ["id", "view_count", "download_count", "bookmark_count", "created_at", "updated_at"]
def get_bookmark_count(self, obj):
from apps.bookmark.models.bookmark import Bookmark
return Bookmark.objects.filter(service=Bookmark.ServiceChoices.LIBRARY, content_id=obj.id, status=True).count()
def create(self, validated_data): def create(self, validated_data):
validated_data.pop("remove_thumbnail", False) validated_data.pop("remove_thumbnail", False)

Loading…
Cancel
Save