Prevent generation of useless migrations upon settings change

This commit is contained in:
Skia 2018-04-26 20:18:24 +02:00
parent 01240ce75e
commit 9146251642
6 changed files with 77 additions and 6 deletions

View File

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
import club.models
class Migration(migrations.Migration):
dependencies = [
('club', '0010_auto_20170912_2028'),
]
operations = [
migrations.AlterField(
model_name='club',
name='owner_group',
field=models.ForeignKey(default=club.models.Club.get_default_owner_group, related_name='owned_club', to='core.Group'),
),
]

View File

@ -62,9 +62,9 @@ class Club(models.Model):
is_active = models.BooleanField(_('is active'), default=True)
short_description = models.CharField(_('short description'), max_length=1000, default='', blank=True, null=True)
address = models.CharField(_('address'), max_length=254)
# email = models.EmailField(_('email address'), unique=True) # This should, and will be generated automatically
owner_group = models.ForeignKey(Group, related_name="owned_club",
default=settings.SITH_GROUP_ROOT_ID)
# This function prevents generating migration upon settings change
def get_default_owner_group(): return settings.SITH_GROUP_ROOT_ID
owner_group = models.ForeignKey(Group, related_name="owned_club", default=get_default_owner_group)
edit_groups = models.ManyToManyField(Group, related_name="editable_club", blank=True)
view_groups = models.ManyToManyField(Group, related_name="viewable_club", blank=True)
home = models.OneToOneField(SithFile, related_name='home_of_club', verbose_name=_("home"), null=True, blank=True,

View File

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
import core.models
class Migration(migrations.Migration):
dependencies = [
('core', '0028_auto_20171216_2044'),
]
operations = [
migrations.AlterField(
model_name='page',
name='owner_group',
field=models.ForeignKey(verbose_name='owner group', default=core.models.Page.get_default_owner_group, related_name='owned_page', to='core.Group'),
),
]

View File

@ -920,8 +920,10 @@ class Page(models.Model):
# Attention: this field may not be valid until you call save(). It's made for fast query, but don't rely on it when
# playing with a Page object, use get_full_name() instead!
_full_name = models.CharField(_('page name'), max_length=255, blank=True)
# This function prevents generating migration upon settings change
def get_default_owner_group(): return settings.SITH_GROUP_ROOT_ID
owner_group = models.ForeignKey(Group, related_name="owned_page", verbose_name=_("owner group"),
default=settings.SITH_GROUP_ROOT_ID)
default=get_default_owner_group)
edit_groups = models.ManyToManyField(Group, related_name="editable_page", verbose_name=_("edit group"), blank=True)
view_groups = models.ManyToManyField(Group, related_name="viewable_page", verbose_name=_("view group"), blank=True)
lock_user = models.ForeignKey(User, related_name="locked_pages", verbose_name=_("lock user"), blank=True, null=True, default=None)

View File

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
import forum.models
class Migration(migrations.Migration):
dependencies = [
('forum', '0005_forumtopic_subscribed_users'),
]
operations = [
migrations.AlterField(
model_name='forum',
name='edit_groups',
field=models.ManyToManyField(blank=True, default=forum.models.Forum.get_default_edit_group, related_name='editable_forums', to='core.Group'),
),
migrations.AlterField(
model_name='forum',
name='view_groups',
field=models.ManyToManyField(blank=True, default=forum.models.Forum.get_default_view_group, related_name='viewable_forums', to='core.Group'),
),
]

View File

@ -38,6 +38,7 @@ from core.models import User, Group
from club.models import Club
class Forum(models.Model):
"""
The Forum class, made as a tree to allow nice tidy organization
@ -46,6 +47,9 @@ class Forum(models.Model):
edit_groups allows to put any group as a forum admin
view_groups allows some groups to view a forum
"""
# Those functions prevent generating migration upon settings changes
def get_default_edit_group(): return [settings.SITH_GROUP_OLD_SUBSCRIBERS_ID]
def get_default_view_group(): return [settings.SITH_GROUP_PUBLIC_ID]
id = models.AutoField(primary_key=True, db_index=True)
name = models.CharField(_('name'), max_length=64)
description = models.CharField(_('description'), max_length=512, default="")
@ -54,9 +58,9 @@ class Forum(models.Model):
owner_club = models.ForeignKey(Club, related_name="owned_forums", verbose_name=_("owner club"),
default=settings.SITH_MAIN_CLUB_ID)
edit_groups = models.ManyToManyField(Group, related_name="editable_forums", blank=True,
default=[settings.SITH_GROUP_OLD_SUBSCRIBERS_ID])
default=get_default_edit_group)
view_groups = models.ManyToManyField(Group, related_name="viewable_forums", blank=True,
default=[settings.SITH_GROUP_PUBLIC_ID])
default=get_default_view_group)
number = models.IntegerField(_("number to choose a specific forum ordering"), default=1)
_last_message = models.ForeignKey('ForumMessage', related_name="forums_where_its_last",
verbose_name=_("the last message"), null=True, on_delete=models.SET_NULL)