fix clean method for eventinstance
You can no longer save eventinstances where the camp year doesnt match for its location and event.
This commit is contained in:
parent
5b1d1c79e9
commit
d4ba512920
|
@ -9,12 +9,11 @@ from datetime import timedelta
|
||||||
from django.contrib.postgres.fields import DateTimeRangeField
|
from django.contrib.postgres.fields import DateTimeRangeField
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.core.exceptions import ObjectDoesNotExist
|
from django.core.exceptions import ObjectDoesNotExist, ValidationError
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
from django.utils.text import slugify
|
from django.utils.text import slugify
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.exceptions import ValidationError
|
|
||||||
from django.core.urlresolvers import reverse_lazy
|
from django.core.urlresolvers import reverse_lazy
|
||||||
from django.core.files.storage import FileSystemStorage
|
from django.core.files.storage import FileSystemStorage
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
@ -478,13 +477,9 @@ class EventInstance(CampRelatedModel):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return '%s (%s)' % (self.event, self.when)
|
return '%s (%s)' % (self.event, self.when)
|
||||||
|
|
||||||
def __clean__(self):
|
def clean(self):
|
||||||
errors = []
|
|
||||||
if self.location.camp != self.event.camp:
|
if self.location.camp != self.event.camp:
|
||||||
errors.append(ValidationError({'location', "Error: This location belongs to a different camp"}))
|
raise ValidationError({'location': 'Error: This location belongs to a different camp'})
|
||||||
|
|
||||||
if errors:
|
|
||||||
raise ValidationError(errors)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def camp(self):
|
def camp(self):
|
||||||
|
|
Loading…
Reference in a new issue