class PostbackURL(models.Model): event = models.ForeignKey('Event', on_delete=models.PROTECT, verbose_name='Event', null=False, blank=False, related_name='postbacks') url = models.URLField(blank=False, null=False, verbose_name='URL') class Meta: app_label = 'tracker'
class Runner(models.Model): class _Manager(models.Manager): def get_by_natural_key(self, name): return self.get(name__iexact=name) def get_or_create_by_natural_key(self, name): return self.get_or_create(name=name) class Meta: app_label = 'tracker' ordering = ('name', ) objects = _Manager() name = models.CharField(max_length=64, unique=True) stream = models.URLField(max_length=128, blank=True) twitter = models.SlugField(max_length=15, blank=True) youtube = models.SlugField(max_length=20, blank=True) donor = models.OneToOneField('tracker.Donor', blank=True, null=True, on_delete=models.PROTECT) def natural_key(self): return (self.name, ) def __str__(self): return self.name
class Runner(models.Model): class _Manager(models.Manager): def get_by_natural_key(self, name): return self.get(name__iexact=name) def get_or_create_by_natural_key(self, name): return self.get_or_create(name__iexact=name, defaults={'name': name}) class Meta: app_label = 'tracker' objects = _Manager() name = models.CharField( max_length=64, unique=True, error_messages={ 'unique': 'Runner with this case-insensitive Name already exists.' }, ) stream = models.URLField(max_length=128, blank=True) twitter = models.SlugField(max_length=15, blank=True) youtube = models.SlugField(max_length=20, blank=True) platform = models.CharField( max_length=20, default='TWITCH', choices=( ('TWITCH', 'Twitch'), ('MIXER', 'Mixer'), ('FACEBOOK', 'Facebook'), ('YOUTUBE', 'Youtube'), ), help_text='Streaming Platforms', ) pronouns = models.CharField(max_length=20, blank=True, help_text='They/Them') donor = models.OneToOneField( 'tracker.Donor', blank=True, null=True, on_delete=models.SET_NULL ) def validate_unique(self, exclude=None): case_insensitive = Runner.objects.filter(name__iexact=self.name) if self.id: case_insensitive = case_insensitive.exclude(id=self.id) case_insensitive = case_insensitive.exists() try: super(Runner, self).validate_unique(exclude) except ValidationError as e: if case_insensitive: e.error_dict.setdefault('name', []).append( self.unique_error_message(Runner, ['name']) ) raise if case_insensitive: raise self.unique_error_message(Runner, ['name']) def natural_key(self): return (self.name,) def __str__(self): return self.name