Skip to content

Commit

Permalink
Don't allow people to have more than five websites.
Browse files Browse the repository at this point in the history
  • Loading branch information
colons committed Nov 6, 2023
1 parent d3e604a commit 564e44c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion nkdsu/apps/vote/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,21 +488,29 @@ def get_toggle_abuser_url(self) -> str:
return reverse('vote:admin:toggle_local_abuser', kwargs={'user_id': self.pk})


MAX_WEBSITES = 5


class UserWebsite(CleanOnSaveMixin, models.Model):
class Meta:
constraints = [
UniqueConstraint(
fields=['url', 'profile'],
name='unique_url_per_profile',
violation_error_message="You can't provide the same URL more than once",
)
),
]

url = models.URLField()
profile = models.ForeignKey(
Profile, related_name='websites', on_delete=models.CASCADE
)

def clean(self) -> None:
super().clean()
if self._state.adding and self.profile.websites.count() >= MAX_WEBSITES:
raise ValidationError('You cannot have any more websites')

@property
def icon(self) -> str:
"""
Expand Down

0 comments on commit 564e44c

Please sign in to comment.