diff options
Diffstat (limited to 'api/models.py')
-rw-r--r-- | api/models.py | 102 |
1 files changed, 65 insertions, 37 deletions
diff --git a/api/models.py b/api/models.py index 4e4de9e0..6b681ebc 100644 --- a/api/models.py +++ b/api/models.py @@ -1,31 +1,80 @@ +from operator import itemgetter + from django.core.validators import MaxValueValidator, MinValueValidator, RegexValidator from django.db import models -class DocumentationLink(models.Model): +class ModelReprMixin: + """ + Adds a `__repr__` method to the model subclassing this + mixin which will display the model's class name along + with all parameters used to construct the object. + """ + + def __repr__(self): + attributes = ' '.join( + f'{attribute}={value!r}' + for attribute, value in sorted( + self.__dict__.items(), + key=itemgetter(0) + ) + if not attribute.startswith('_') + ) + return f'<{self.__class__.__name__}({attributes})>' + + +class DocumentationLink(ModelReprMixin, models.Model): """A documentation link used by the `!docs` command of the bot.""" - package = models.CharField(primary_key=True, max_length=50) - base_url = models.URLField() - inventory_url = models.URLField() + package = models.CharField( + primary_key=True, + max_length=50, + help_text="The Python package name that this documentation link belongs to." + ) + base_url = models.URLField( + help_text=( + "The base URL from which documentation will be available for this project. " + "Used to generate links to various symbols within this package." + ) + ) + inventory_url = models.URLField( + help_text="The URL at which the Sphinx inventory is available for this package." + ) + def __str__(self): + return f"{self.package} - {self.base_url}" -class OffTopicChannelName(models.Model): + +class OffTopicChannelName(ModelReprMixin, models.Model): name = models.CharField( primary_key=True, max_length=96, - validators=(RegexValidator(regex=r'^[a-z0-9-]+$'),) + validators=(RegexValidator(regex=r'^[a-z0-9-]+$'),), + help_text="The actual channel name that will be used on our Discord server." ) + def __str__(self): + return self.name + -class SnakeName(models.Model): +class SnakeName(ModelReprMixin, models.Model): """A snake name used by the bot's snake cog.""" - name = models.CharField(primary_key=True, max_length=100) - scientific = models.CharField(max_length=150) + name = models.CharField( + primary_key=True, + max_length=100, + help_text="The regular name for this snake, e.g. 'Python'." + ) + scientific = models.CharField( + max_length=150, + help_text="The scientific name for this snake, e.g. 'Python bivittatus'." + ) + + def __str__(self): + return f"{self.name} ({self.scientific})" -class Role(models.Model): +class Role(ModelReprMixin, models.Model): """A role on our Discord server.""" id = models.BigIntegerField( # noqa @@ -65,8 +114,11 @@ class Role(models.Model): help_text="The integer value of the permission bitset of this role from Discord." ) + def __str__(self): + return self.name + -class Member(models.Model): +class Member(ModelReprMixin, models.Model): """A member of our Discord server.""" id = models.BigIntegerField( # noqa @@ -105,29 +157,5 @@ class Member(models.Model): help_text="Any roles this user has on our server." ) - -class Tag(models.Model): - """A tag providing (hopefully) useful content, shown by the bot.""" - - author = models.ForeignKey( - Member, - help_text="The user that originally created this tag.", - on_delete=models.CASCADE - ) - title = models.CharField( - max_length=256, - help_text="The title of this tag, displayed in the Embed.", - unique=True - ) - content = models.CharField( - max_length=2048, - help_text="The content of this tag, displayed in the Embed." - ) - image_url = models.URLField( - null=True, - help_text="An optional image to display in the tag embed." - ) - thumbnail_url = models.URLField( - null=True, - help_text="An optional thumbnail to display in the tag embed." - ) + def __str__(self): + return f"{self.name}#{self.discriminator}" |