10 changed files with 264 additions and 6 deletions
-
5apps/library/admin.py
-
24apps/library/doc.py
-
79apps/library/management/commands/populate_author_fields.py
-
73apps/library/migrations/0005_author_date_of_birth_author_date_of_death_and_more.py
-
18apps/library/migrations/0006_alter_author_number_of_volumes.py
-
18apps/library/models.py
-
34apps/library/serializers.py
-
15apps/library/serializers_admin.py
-
2apps/library/views.py
-
2entrypoint.sh
@ -0,0 +1,79 @@ |
|||||
|
from django.core.management.base import BaseCommand |
||||
|
from django.db import transaction |
||||
|
from apps.library.models import Author |
||||
|
|
||||
|
class Command(BaseCommand): |
||||
|
help = 'Populates the newly added fields for all existing authors with sample English data' |
||||
|
|
||||
|
def handle(self, *args, **options): |
||||
|
self.stdout.write(self.style.WARNING('--- Starting Author Fields Population ---')) |
||||
|
|
||||
|
authors = Author.objects.all() |
||||
|
if not authors.exists(): |
||||
|
self.stdout.write(self.style.ERROR('No authors found in the database.')) |
||||
|
return |
||||
|
|
||||
|
self.stdout.write(self.style.SUCCESS(f'Found {authors.count()} authors. Commencing update...')) |
||||
|
|
||||
|
updated_count = 0 |
||||
|
with transaction.atomic(): |
||||
|
for author in authors: |
||||
|
# 1. Researcher / Editor |
||||
|
if not author.researcher_editor: |
||||
|
author.researcher_editor = f"Edited and researched by {author.full_name}" |
||||
|
|
||||
|
# 2. Publisher |
||||
|
if not author.publisher: |
||||
|
author.publisher = "Imam Javad Publishing Institute" |
||||
|
|
||||
|
# 3. Publication Place |
||||
|
if not author.publication_place: |
||||
|
author.publication_place = "Qom, Iran" |
||||
|
|
||||
|
# 4. Edition Statement |
||||
|
if not author.edition_statement: |
||||
|
author.edition_statement = "First Edition (Revised)" |
||||
|
|
||||
|
# 5. Year |
||||
|
if not author.year: |
||||
|
author.year = "1448 AH" |
||||
|
|
||||
|
# 6. Number of Volumes |
||||
|
if not author.number_of_volumes: |
||||
|
author.number_of_volumes = 5 |
||||
|
|
||||
|
# 7. Notes |
||||
|
if not author.notes: |
||||
|
author.notes = f"This edition contains annotations and key commentaries regarding the works of {author.full_name}." |
||||
|
|
||||
|
# 8. Online Source |
||||
|
if not author.online_source: |
||||
|
author.online_source = "https://imamjavad.nwhco.ir" |
||||
|
|
||||
|
# 9. Tag |
||||
|
if not author.tag: |
||||
|
author.tag = "Reference Books" |
||||
|
|
||||
|
# 10. Copy thumbnail to image if thumbnail exists and image doesn't |
||||
|
if author.thumbnail and not author.image: |
||||
|
author.image = author.thumbnail |
||||
|
|
||||
|
# 11. Date of Birth (text) |
||||
|
if not author.date_of_birth: |
||||
|
if author.birth_date: |
||||
|
author.date_of_birth = f"{author.birth_date.year} AD" |
||||
|
else: |
||||
|
author.date_of_birth = "Around 4th Century AH" |
||||
|
|
||||
|
# 12. Date of Death (text) |
||||
|
if not author.date_of_death: |
||||
|
if author.death_date: |
||||
|
author.date_of_death = f"{author.death_date.year} AD" |
||||
|
else: |
||||
|
author.date_of_death = "Around 5th Century AH" |
||||
|
|
||||
|
author.save() |
||||
|
updated_count += 1 |
||||
|
self.stdout.write(f"Updated author: {author.full_name}") |
||||
|
|
||||
|
self.stdout.write(self.style.SUCCESS(f'--- Finished! Successfully updated {updated_count} authors ---')) |
||||
@ -0,0 +1,73 @@ |
|||||
|
# Generated by Django 4.2.30 on 2026-07-16 13:25 |
||||
|
|
||||
|
from django.db import migrations, models |
||||
|
|
||||
|
|
||||
|
class Migration(migrations.Migration): |
||||
|
|
||||
|
dependencies = [ |
||||
|
('library', '0004_alter_author_slug_alter_book_slug_and_more'), |
||||
|
] |
||||
|
|
||||
|
operations = [ |
||||
|
migrations.AddField( |
||||
|
model_name='author', |
||||
|
name='date_of_birth', |
||||
|
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Date of Birth'), |
||||
|
), |
||||
|
migrations.AddField( |
||||
|
model_name='author', |
||||
|
name='date_of_death', |
||||
|
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Date of Death'), |
||||
|
), |
||||
|
migrations.AddField( |
||||
|
model_name='author', |
||||
|
name='edition_statement', |
||||
|
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Edition Statement'), |
||||
|
), |
||||
|
migrations.AddField( |
||||
|
model_name='author', |
||||
|
name='image', |
||||
|
field=models.ImageField(blank=True, help_text='image allowed', null=True, upload_to='author_images/', verbose_name='Image'), |
||||
|
), |
||||
|
migrations.AddField( |
||||
|
model_name='author', |
||||
|
name='notes', |
||||
|
field=models.TextField(blank=True, null=True, verbose_name='Notes'), |
||||
|
), |
||||
|
migrations.AddField( |
||||
|
model_name='author', |
||||
|
name='number_of_volumes', |
||||
|
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Number of Volumes'), |
||||
|
), |
||||
|
migrations.AddField( |
||||
|
model_name='author', |
||||
|
name='online_source', |
||||
|
field=models.URLField(blank=True, max_length=512, null=True, verbose_name='Online Source'), |
||||
|
), |
||||
|
migrations.AddField( |
||||
|
model_name='author', |
||||
|
name='publication_place', |
||||
|
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Publication Place'), |
||||
|
), |
||||
|
migrations.AddField( |
||||
|
model_name='author', |
||||
|
name='publisher', |
||||
|
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Publisher'), |
||||
|
), |
||||
|
migrations.AddField( |
||||
|
model_name='author', |
||||
|
name='researcher_editor', |
||||
|
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Researcher / Editor'), |
||||
|
), |
||||
|
migrations.AddField( |
||||
|
model_name='author', |
||||
|
name='tag', |
||||
|
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Tag'), |
||||
|
), |
||||
|
migrations.AddField( |
||||
|
model_name='author', |
||||
|
name='year', |
||||
|
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Year'), |
||||
|
), |
||||
|
] |
||||
@ -0,0 +1,18 @@ |
|||||
|
# Generated by Django 4.2.30 on 2026-07-16 13:44 |
||||
|
|
||||
|
from django.db import migrations, models |
||||
|
|
||||
|
|
||||
|
class Migration(migrations.Migration): |
||||
|
|
||||
|
dependencies = [ |
||||
|
('library', '0005_author_date_of_birth_author_date_of_death_and_more'), |
||||
|
] |
||||
|
|
||||
|
operations = [ |
||||
|
migrations.AlterField( |
||||
|
model_name='author', |
||||
|
name='number_of_volumes', |
||||
|
field=models.IntegerField(blank=True, null=True, verbose_name='Number of Volumes'), |
||||
|
), |
||||
|
] |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue