reverse manytomany field between access restrictions and their groups
This commit is contained in:
parent
34199b2bf3
commit
450c9486c0
3 changed files with 55 additions and 10 deletions
|
@ -0,0 +1,41 @@
|
|||
# Generated by Django 5.0.8 on 2024-12-11 13:24
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
def forwards_func(apps, schema_editor):
|
||||
AccessRestrictionGroup = apps.get_model('mapdata', 'AccessRestrictionGroup')
|
||||
for group in AccessRestrictionGroup.objects.prefetch_related("accessrestrictions").all():
|
||||
group.members.set(group.accessrestrictions.all())
|
||||
|
||||
|
||||
def backwards_func(apps, schema_editor):
|
||||
AccessRestrictionGroup = apps.get_model('mapdata', 'AccessRestrictionGroup')
|
||||
for group in AccessRestrictionGroup.objects.prefetch_related("members").all():
|
||||
group.accessrestrictions.set(group.members.all())
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('mapdata', '0113_locationgroup_can_report_mistake'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='accessrestrictiongroup',
|
||||
name='members',
|
||||
field=models.ManyToManyField(blank=True, to='mapdata.accessrestriction', verbose_name='Access Restrictions'),
|
||||
),
|
||||
migrations.RunPython(forwards_func, backwards_func),
|
||||
migrations.RemoveField(
|
||||
model_name='accessrestriction',
|
||||
name='groups',
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='accessrestrictiongroup',
|
||||
name='members',
|
||||
field=models.ManyToManyField(blank=True, related_name='groups', to='mapdata.accessrestriction',
|
||||
verbose_name='Access Restrictions'),
|
||||
),
|
||||
]
|
Loading…
Add table
Add a link
Reference in a new issue