Repos / pytaku / 2715846b1f
commit 2715846b1f248c022e40876d47bfabbe3f5ecb6b
Author: Bùi Thành Nhân <hi@imnhan.com>
Date: Tue May 5 12:39:46 2020 +0700
better chapter number, create migration
diff --git a/README.md b/README.md
index 6c76f86..fbc6196 100644
--- a/README.md
+++ b/README.md
@@ -31,7 +31,7 @@ # (see [tool.poetry.scripts] in pyproject.toml)
pyenv deactivate && pyenv activate
# generate initial config for local dev - should work out of the box with the
-# db provided docker-compose above.
+# db provided by docker-compose above.
make localconfig
make dev
diff --git a/src/pytaku/settings.py b/src/pytaku/settings.py
index dac1ae6..d0ab210 100644
--- a/src/pytaku/settings.py
+++ b/src/pytaku/settings.py
@@ -41,6 +41,7 @@
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
+ "pytaku_web",
]
MIDDLEWARE = [
diff --git a/src/pytaku/test_settings.py b/src/pytaku/test_settings.py
new file mode 100644
index 0000000..9f5b010
--- /dev/null
+++ b/src/pytaku/test_settings.py
@@ -0,0 +1,4 @@
+from .settings import * # noqa
+
+DEFAULT_FILE_STORAGE = "django.core.files.storage.FileSystemStorage"
+MEDIA_ROOT = "test_media"
diff --git a/src/pytaku_web/migrations/0001_initial.py b/src/pytaku_web/migrations/0001_initial.py
new file mode 100644
index 0000000..0bdf305
--- /dev/null
+++ b/src/pytaku_web/migrations/0001_initial.py
@@ -0,0 +1,54 @@
+# Generated by Django 3.0.5 on 2020-05-05 05:41
+
+import django.contrib.postgres.fields
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ initial = True
+
+ dependencies = [
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='Title',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('site', models.CharField(max_length=50)),
+ ('original_id', models.CharField(max_length=255)),
+ ('name', models.CharField(max_length=255)),
+ ('alt_names', django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=255), default=list, size=None)),
+ ('cover', models.CharField(max_length=255)),
+ ('descriptions', django.contrib.postgres.fields.ArrayField(base_field=models.TextField(), default=list, size=None)),
+ ('publication_status', models.CharField(max_length=100)),
+ ('authors', django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=100), default=list, size=None)),
+ ('tags', django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=50), default=list, size=None)),
+ ],
+ options={
+ 'db_table': 'title',
+ },
+ ),
+ migrations.CreateModel(
+ name='Chapter',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('original_id', models.CharField(max_length=255)),
+ ('name', models.CharField(max_length=255)),
+ ('num_major', models.PositiveIntegerField()),
+ ('num_minor', models.PositiveIntegerField(blank=True, null=True)),
+ ('pages', django.contrib.postgres.fields.ArrayField(base_field=models.TextField(), default=list, size=None)),
+ ('title', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='chapters', to='pytaku_web.Title')),
+ ],
+ options={
+ 'db_table': 'chapter',
+ 'ordering': ['num_major', 'num_minor'],
+ },
+ ),
+ migrations.AddConstraint(
+ model_name='chapter',
+ constraint=models.UniqueConstraint(fields=('title', 'num_major', 'num_minor'), name='unique_number_within_title'),
+ ),
+ ]
diff --git a/src/pytaku_web/models.py b/src/pytaku_web/models.py
index d465aae..3e94a2a 100644
--- a/src/pytaku_web/models.py
+++ b/src/pytaku_web/models.py
@@ -25,9 +25,11 @@ class Meta:
db_table = "chapter"
constraints = [
models.UniqueConstraint(
- fields=["title", "ordering"], name="unique_order_within_title"
+ fields=["title", "num_major", "num_minor"],
+ name="unique_number_within_title",
)
]
+ ordering = ["num_major", "num_minor"]
original_id = models.CharField(max_length=255)
name = models.CharField(max_length=255)