-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from daniviga/catalogue
Introduce the concept of catalogs, improve books and code refactoring
- Loading branch information
Showing
27 changed files
with
560 additions
and
300 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
141 changes: 141 additions & 0 deletions
141
ram/bookshelf/migrations/0016_basebook_book_catalogue.py
This file contains 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 |
---|---|---|
@@ -0,0 +1,141 @@ | ||
# Generated by Django 5.1.2 on 2024-11-27 16:35 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
def basebook_to_book(apps, schema_editor): | ||
basebook = apps.get_model("bookshelf", "BaseBook") | ||
book = apps.get_model("bookshelf", "Book") | ||
for row in basebook.objects.all(): | ||
b = book.objects.create( | ||
basebook_ptr=row, | ||
title=row.old_title, | ||
publisher=row.old_publisher, | ||
) | ||
b.authors.set(row.old_authors.all()) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("bookshelf", "0015_alter_book_authors"), | ||
("metadata", "0019_alter_scale_gauge"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterModelOptions( | ||
name="Book", | ||
options={"ordering": ["creation_time"]}, | ||
), | ||
migrations.RenameModel( | ||
old_name="BookImage", | ||
new_name="BaseBookImage", | ||
), | ||
migrations.RenameModel( | ||
old_name="BookProperty", | ||
new_name="BaseBookProperty", | ||
), | ||
migrations.RenameModel( | ||
old_name="Book", | ||
new_name="BaseBook", | ||
), | ||
migrations.RenameField( | ||
model_name="basebook", | ||
old_name="title", | ||
new_name="old_title", | ||
), | ||
migrations.RenameField( | ||
model_name="basebook", | ||
old_name="authors", | ||
new_name="old_authors", | ||
), | ||
migrations.RenameField( | ||
model_name="basebook", | ||
old_name="publisher", | ||
new_name="old_publisher", | ||
), | ||
migrations.AlterModelOptions( | ||
name="basebookimage", | ||
options={"ordering": ["order"], "verbose_name_plural": "Images"}, | ||
), | ||
migrations.CreateModel( | ||
name="Book", | ||
fields=[ | ||
( | ||
"basebook_ptr", | ||
models.OneToOneField( | ||
auto_created=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
parent_link=True, | ||
primary_key=True, | ||
serialize=False, | ||
to="bookshelf.basebook", | ||
), | ||
), | ||
("title", models.CharField(max_length=200)), | ||
( | ||
"authors", | ||
models.ManyToManyField( | ||
blank=True, | ||
to="bookshelf.author" | ||
), | ||
), | ||
( | ||
"publisher", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
to="bookshelf.publisher" | ||
), | ||
), | ||
], | ||
options={ | ||
"ordering": ["title"], | ||
}, | ||
), | ||
migrations.RunPython( | ||
basebook_to_book, | ||
reverse_code=migrations.RunPython.noop | ||
), | ||
migrations.RemoveField( | ||
model_name="basebook", | ||
name="old_title", | ||
), | ||
migrations.RemoveField( | ||
model_name="basebook", | ||
name="old_authors", | ||
), | ||
migrations.RemoveField( | ||
model_name="basebook", | ||
name="old_publisher", | ||
), | ||
migrations.CreateModel( | ||
name="Catalog", | ||
fields=[ | ||
( | ||
"basebook_ptr", | ||
models.OneToOneField( | ||
auto_created=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
parent_link=True, | ||
primary_key=True, | ||
serialize=False, | ||
to="bookshelf.basebook", | ||
), | ||
), | ||
("years", models.CharField(max_length=12)), | ||
( | ||
"manufacturer", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
to="metadata.manufacturer", | ||
), | ||
), | ||
("scales", models.ManyToManyField(to="metadata.scale")), | ||
], | ||
options={ | ||
"ordering": ["manufacturer", "publication_year"], | ||
}, | ||
bases=("bookshelf.basebook",), | ||
), | ||
] |
52 changes: 52 additions & 0 deletions
52
ram/bookshelf/migrations/0017_alter_basebook_options_basebookdocument.py
This file contains 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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Generated by Django 5.1.2 on 2024-12-22 20:38 | ||
|
||
import django.db.models.deletion | ||
import ram.utils | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("bookshelf", "0016_basebook_book_catalogue"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterModelOptions( | ||
name="basebook", | ||
options={}, | ||
), | ||
migrations.CreateModel( | ||
name="BaseBookDocument", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("description", models.CharField(blank=True, max_length=128)), | ||
( | ||
"file", | ||
models.FileField( | ||
storage=ram.utils.DeduplicatedStorage(), upload_to="files/" | ||
), | ||
), | ||
("private", models.BooleanField(default=False)), | ||
( | ||
"book", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="document", | ||
to="bookshelf.basebook", | ||
), | ||
), | ||
], | ||
options={ | ||
"unique_together": {("book", "file")}, | ||
}, | ||
), | ||
] |
Oops, something went wrong.