Update kaehmy BaseRole
This commit is contained in:
@@ -0,0 +1,29 @@
|
|||||||
|
# Generated by Django 2.2.28 on 2022-07-26 17:15
|
||||||
|
|
||||||
|
from unicodedata import category
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
def copyBaseRolesToNewTable(apps, schema_editor):
|
||||||
|
Old = apps.get_model("kaehmy", "KaehmyBaseRole")
|
||||||
|
New = apps.get_model("kaehmy", "BaseRole")
|
||||||
|
for bases in Old.objects.all():
|
||||||
|
New.objects.create(
|
||||||
|
id=bases.id,
|
||||||
|
name=bases.name,
|
||||||
|
is_board=bases.is_board,
|
||||||
|
category=bases.category,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("kaehmy", "0008_baserole"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunPython(
|
||||||
|
copyBaseRolesToNewTable, reverse_code=migrations.RunPython.noop
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
# Generated by Django 2.2.28 on 2022-07-26 17:33
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
from sikweb.custom_operations import AlterModelBases
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("kaehmy", "0009_auto_20220726_2015"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
AlterModelBases("customrole", (models.Model,)),
|
||||||
|
AlterModelBases("presetrole", (models.Model,)),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="customrole",
|
||||||
|
name="kaehmybaserole_ptr",
|
||||||
|
field=models.OneToOneField(
|
||||||
|
auto_created=True,
|
||||||
|
on_delete=django.db.models.deletion.CASCADE,
|
||||||
|
parent_link=True,
|
||||||
|
primary_key=True,
|
||||||
|
serialize=False,
|
||||||
|
to="BaseRole",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="presetrole",
|
||||||
|
name="kaehmybaserole_ptr",
|
||||||
|
field=models.OneToOneField(
|
||||||
|
auto_created=True,
|
||||||
|
on_delete=django.db.models.deletion.CASCADE,
|
||||||
|
parent_link=True,
|
||||||
|
primary_key=True,
|
||||||
|
serialize=False,
|
||||||
|
to="BaseRole",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name="customrole",
|
||||||
|
old_name="kaehmybaserole_ptr",
|
||||||
|
new_name="baserole_ptr",
|
||||||
|
),
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name="presetrole",
|
||||||
|
old_name="kaehmybaserole_ptr",
|
||||||
|
new_name="baserole_ptr",
|
||||||
|
),
|
||||||
|
]
|
||||||
+2
-2
@@ -67,7 +67,7 @@ class KaehmyBaseRole(OldBaseRole):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class PresetRole(KaehmyBaseRole):
|
class PresetRole(BaseRole):
|
||||||
"""Model for kaehmy role."""
|
"""Model for kaehmy role."""
|
||||||
|
|
||||||
description = models.TextField(_("Description"))
|
description = models.TextField(_("Description"))
|
||||||
@@ -77,7 +77,7 @@ class PresetRole(KaehmyBaseRole):
|
|||||||
verbose_name_plural = _("Preset kaehmy roles")
|
verbose_name_plural = _("Preset kaehmy roles")
|
||||||
|
|
||||||
|
|
||||||
class CustomRole(KaehmyBaseRole):
|
class CustomRole(BaseRole):
|
||||||
"""Model representing a user-specified custom occupation."""
|
"""Model representing a user-specified custom occupation."""
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
# contents of yourapp/migrations/custom_operations.py
|
||||||
|
|
||||||
|
from django.db.migrations.operations.models import ModelOperation
|
||||||
|
|
||||||
|
|
||||||
|
class AlterModelBases(ModelOperation):
|
||||||
|
reduce_to_sql = False
|
||||||
|
reversible = True
|
||||||
|
|
||||||
|
def __init__(self, name, bases):
|
||||||
|
self.bases = bases
|
||||||
|
super().__init__(name)
|
||||||
|
|
||||||
|
def state_forwards(self, app_label, state):
|
||||||
|
"""
|
||||||
|
Overwrite a models base classes with a custom list of
|
||||||
|
bases instead, then force Django to reload the model
|
||||||
|
with this (probably completely) different class hierarchy.
|
||||||
|
"""
|
||||||
|
state.models[app_label, self.name_lower].bases = self.bases
|
||||||
|
state.reload_model(app_label, self.name_lower)
|
||||||
|
|
||||||
|
def database_forwards(self, app_label, schema_editor, from_state, to_state):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def database_backwards(self, app_label, schema_editor, from_state, to_state):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def describe(self):
|
||||||
|
return "Update %s bases to %s" % (self.name, self.bases)
|
||||||
Reference in New Issue
Block a user