Add a clean method on TicketCC model in order to be sure not to add a user who doesn't have an email address.

This commit is contained in:
bbe 2020-10-31 18:24:22 +01:00
parent 79d8046694
commit 7564c5739b

View File

@ -10,7 +10,7 @@ models.py - Model (and hence database) definitions. This is the core of the
from django.contrib.auth.models import Permission from django.contrib.auth.models import Permission
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django.db import models from django.db import models
from django.conf import settings from django.conf import settings
from django.utils import timezone from django.utils import timezone
@ -1666,6 +1666,10 @@ class TicketCC(models.Model):
def __str__(self): def __str__(self):
return '%s for %s' % (self.display, self.ticket.title) return '%s for %s' % (self.display, self.ticket.title)
def clean(self):
if self.user and not self.user.email:
raise ValidationError('User has no email address')
class CustomFieldManager(models.Manager): class CustomFieldManager(models.Manager):