Compare commits

...

2 Commits

Author SHA1 Message Date
Pavel 'LEdoian' Turinsky a23daf8b97 Další pokus o migraci, I guess (po týdnu, lol) 8 months ago
Pavel 'LEdoian' Turinsky 457236c21a Vzor migrace pro create 8 months ago
  1. 12
      personalni/migrations/0003_initial.py
  2. 52
      split-apps-meta/create-ct-hack.py
  3. 1
      split-apps-meta/create.notes

12
personalni/migrations/0003_initial.py

@ -5,6 +5,17 @@ import django.utils.timezone
import django_countries.fields import django_countries.fields
import imagekit.models.fields import imagekit.models.fields
def nastav_nove_contenttypes(apps, schema_editor):
ContentType = apps.get_model('contenttypes', 'ContentType')
for m in ('resitel', 'organizator', 'osoba', 'skola', 'prijemce'):
oct = ContentType.objects.filter(app_label='seminar', model=m)
oct.update(app_label='personalni')
def nastav_stare_contenttypes(apps, schema_editor):
ContentType = apps.get_model('contenttypes', 'ContentType')
for m in ('resitel', 'organizator', 'osoba', 'skola', 'prijemce'):
nct = ContentType.objects.filter(app_label='personalni', model=m)
nct.update(app_label='seminar')
class Migration(migrations.Migration): class Migration(migrations.Migration):
@ -16,6 +27,7 @@ class Migration(migrations.Migration):
] ]
operations = [ operations = [
migrations.RunPython(nastav_nove_contenttypes, nastav_stare_contenttypes),
migrations.CreateModel( migrations.CreateModel(
name='Organizator', name='Organizator',
fields=[ fields=[

52
split-apps-meta/create-ct-hack.py

@ -0,0 +1,52 @@
# Správná migrace vypadá takto:
# Generated by Django 3.2.23 on 2023-12-11 19:19
def nastav_nove_contenttypes(apps, schema_editor):
ContentType = apps.get_model('contenttypes', 'ContentType')
old_ct = ContentType.objects.filter(app_label='seminar', model='nastaveni')
# Pozn: tohle může být prázdné (pokud Django nedostalo signál o dokončených migracích, např. při vyrábění databáze z nuly)
# Ale .update to nevadí…
old_ct.update(app_label='various')
def nastav_stare_contenttypes(apps, schema_editor):
ContentType = apps.get_model('contenttypes', 'ContentType')
new_ct = ContentType.objects.filter(app_label='various', model='nastaveni')
new_ct.update(app_label='seminar')
class Migration(migrations.Migration):
initial = True
dependencies = [
('seminar', '0115_alter_nastaveni_options'),
]
operations = [
migrations.CreateModel(
name='Nastaveni',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('cena_sous', models.IntegerField(default=1000, verbose_name='Účastnický poplatek za soustředění')),
],
options={
'verbose_name': 'Nastavení semináře',
'db_table': 'seminar_nastaveni',
'managed': False,
},
),
migrations.RunPython(nastav_nove_contenttypes, nastav_stare_contenttypes),
]
#Hack: zkrácení
def nastav_nove_contenttypes(apps, schema_editor):
ContentType = apps.get_model('contenttypes', 'ContentType')
for m in ('resitel', 'organizator', 'osoba', 'skola', 'prijemce'):
ContentType.objects.filter(app_label='seminar', model=m).update(app_label='personalni')
def nastav_stare_contenttypes(apps, schema_editor):
ContentType = apps.get_model('contenttypes', 'ContentType')
for m in ('resitel', 'organizator', 'osoba', 'skola', 'prijemce'):
ContentType.objects.filter(app_label='personalni', model=m).update(app_label='seminar')

1
split-apps-meta/create.notes

@ -1,4 +1,5 @@
Prostě zkopírovat vedle, s původními (=správnými) related names. Prostě zkopírovat vedle, s původními (=správnými) related names.
makemigrations makemigrations
! Doplnit hack kolem content-types
doplnit závislost na unmanage doplnit závislost na unmanage
migrate migrate

Loading…
Cancel
Save