From: Radek Czajka Date: Mon, 23 Mar 2020 15:00:10 +0000 (+0100) Subject: Preliminary catalogue. X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/1b3b64f7afe8ee6944f1f2d82ee5dabf3d8bb48b?ds=sidebyside Preliminary catalogue. --- diff --git a/src/catalogue/admin.py b/src/catalogue/admin.py new file mode 100644 index 00000000..189cd718 --- /dev/null +++ b/src/catalogue/admin.py @@ -0,0 +1,17 @@ +from django.contrib import admin +from . import models + + + +class AuthorAdmin(admin.ModelAdmin): + search_fields = ['name'] + +admin.site.register(models.Author, AuthorAdmin) + + +class BookAdmin(admin.ModelAdmin): + raw_id_fields = ['authors'] + autocomplete_fields = ['translators'] + +admin.site.register(models.Book, BookAdmin) + diff --git a/src/catalogue/migrations/0006_author_book.py b/src/catalogue/migrations/0006_author_book.py new file mode 100644 index 00000000..7cea032d --- /dev/null +++ b/src/catalogue/migrations/0006_author_book.py @@ -0,0 +1,41 @@ +# Generated by Django 3.0.4 on 2020-03-22 23:17 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('catalogue', '0005_auto_20200322_2114'), + ] + + operations = [ + migrations.CreateModel( + name='Author', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=255)), + ('year_of_death', models.SmallIntegerField(blank=True, null=True)), + ('status', models.PositiveSmallIntegerField(blank=True, choices=[('alive', 'Alive'), ('dead', 'Dead'), ('long-dead', 'Long dead'), ('unknown', 'Unknown')], null=True)), + ], + ), + migrations.CreateModel( + name='Book', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('uri', models.CharField(max_length=255)), + ('title', models.CharField(max_length=255)), + ('language', models.CharField(max_length=3)), + ('scans_source', models.CharField(blank=True, max_length=255)), + ('text_source', models.CharField(blank=True, max_length=255)), + ('notes', models.TextField(blank=True)), + ('priority', models.PositiveSmallIntegerField(choices=[(0, 'Low'), (1, 'Medium'), (2, 'High')], default=0)), + ('authors', models.ManyToManyField(to='catalogue.Author')), + ('based_on', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='translation', to='catalogue.Book')), + ('translator', models.ManyToManyField(related_name='translated_book_set', related_query_name='translated_book', to='catalogue.Author')), + ], + ), + ] diff --git a/src/catalogue/migrations/0007_auto_20200322_2326.py b/src/catalogue/migrations/0007_auto_20200322_2326.py new file mode 100644 index 00000000..a1a110a9 --- /dev/null +++ b/src/catalogue/migrations/0007_auto_20200322_2326.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.4 on 2020-03-22 23:26 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('catalogue', '0006_author_book'), + ] + + operations = [ + migrations.AlterField( + model_name='author', + name='status', + field=models.PositiveSmallIntegerField(blank=True, choices=[(1, 'Alive'), (2, 'Dead'), (3, 'Long dead'), (4, 'Unknown')], null=True), + ), + ] diff --git a/src/catalogue/models.py b/src/catalogue/models.py new file mode 100644 index 00000000..4a236b62 --- /dev/null +++ b/src/catalogue/models.py @@ -0,0 +1,38 @@ +from django.db import models +from django.utils.translation import gettext_lazy as _ + + +class Author(models.Model): + name = models.CharField(max_length=255) + year_of_death = models.SmallIntegerField(null=True, blank=True) + status = models.PositiveSmallIntegerField(null=True, blank=True, choices=[ + (1, _('Alive')), + (2, _('Dead')), + (3, _('Long dead')), + (4, _('Unknown')), + ]) + + def __str__(self): + return self.name + + +class Book(models.Model): + uri = models.CharField(max_length=255) + + authors = models.ManyToManyField(Author, blank=True) + translators = models.ManyToManyField(Author, related_name='translated_book_set', related_query_name='translated_book', blank=True) + title = models.CharField(max_length=255) + language = models.CharField(max_length=3) + based_on = models.ForeignKey('self', models.PROTECT, related_name='translation', null=True, blank=True) + + scans_source = models.CharField(max_length=255, blank=True) + text_source = models.CharField(max_length=255, blank=True) + notes = models.TextField(blank=True) + priority = models.PositiveSmallIntegerField(default=0, choices=[ + (0, _('Low')), + (1, _('Medium')), + (2, _('High')), + ]) + + def __str__(self): + return self.title