add a related_name for the camp relation for TeamArea, and a teams property to Camp model to make it easier to get all teams under all teamareas, also add exclude=None to the validate_unique call in our CleanedModel class
This commit is contained in:
parent
60c4bb49fb
commit
fe4e47edb0
|
@ -188,3 +188,10 @@ class Camp(CreatedUpdatedModel, UUIDModel):
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@property
|
||||||
|
def teams(self):
|
||||||
|
""" Return a queryset with all teams under all TeamAreas under this Camp """
|
||||||
|
from teams.models import Team
|
||||||
|
return Team.objects.filter(area__in=self.teamareas.all())
|
||||||
|
|
||||||
|
|
21
src/teams/migrations/0020_auto_20180304_1233.py
Normal file
21
src/teams/migrations/0020_auto_20180304_1233.py
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.10.5 on 2018-03-04 11:33
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('teams', '0019_auto_20180304_1019'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='teamarea',
|
||||||
|
name='camp',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='teamareas', to='camps.Camp'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -18,7 +18,7 @@ class TeamArea(CampRelatedModel):
|
||||||
|
|
||||||
name = models.CharField(max_length=255)
|
name = models.CharField(max_length=255)
|
||||||
description = models.TextField(default='')
|
description = models.TextField(default='')
|
||||||
camp = models.ForeignKey('camps.Camp')
|
camp = models.ForeignKey('camps.Camp', related_name="teamareas", on_delete=models.PROTECT)
|
||||||
responsible = models.ManyToManyField(
|
responsible = models.ManyToManyField(
|
||||||
'auth.User',
|
'auth.User',
|
||||||
related_name='responsible_team_areas'
|
related_name='responsible_team_areas'
|
||||||
|
|
|
@ -20,7 +20,7 @@ class CleanedModel(models.Model):
|
||||||
# which is not supposed to happen. Call them manually one by one instead.
|
# which is not supposed to happen. Call them manually one by one instead.
|
||||||
self.clean_fields()
|
self.clean_fields()
|
||||||
self.clean()
|
self.clean()
|
||||||
self.validate_unique()
|
self.validate_unique(exclude=None)
|
||||||
except ValidationError as e:
|
except ValidationError as e:
|
||||||
message = "Got ValidationError while saving: %s" % e
|
message = "Got ValidationError while saving: %s" % e
|
||||||
if hasattr(self, 'request'):
|
if hasattr(self, 'request'):
|
||||||
|
|
Loading…
Reference in a new issue