From 861f272ccf76abfe317b96827e4632b2657d5d69 Mon Sep 17 00:00:00 2001 From: Sebastiaan Zeeff <33516116+SebastiaanZ@users.noreply.github.com> Date: Fri, 23 Aug 2019 13:26:37 +0200 Subject: Making the comparison operators for Role act like those for d.py Role objects --- pydis_site/apps/api/models/bot/role.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'pydis_site/apps/api/models') diff --git a/pydis_site/apps/api/models/bot/role.py b/pydis_site/apps/api/models/bot/role.py index 836d9f27..58bbf8b4 100644 --- a/pydis_site/apps/api/models/bot/role.py +++ b/pydis_site/apps/api/models/bot/role.py @@ -7,7 +7,12 @@ from pydis_site.apps.api.models.utils import ModelReprMixin class Role(ModelReprMixin, models.Model): - """A role on our Discord server.""" + """ + A role on our Discord server. + + The comparison operators <, <=, >, >=, ==, != act the same as they do with Role-objects of the + discord.py library, see https://discordpy.readthedocs.io/en/latest/api.html#discord.Role + """ id = models.BigIntegerField( primary_key=True, @@ -49,10 +54,14 @@ class Role(ModelReprMixin, models.Model): help_text="The position of the role in the role hierarchy of the Discord Guild." ) - def __str__(self): + def __str__(self) -> str: """Returns the name of the current role, for display purposes.""" return self.name - def __lt__(self, other: Role): + def __lt__(self, other: Role) -> bool: """Compares the roles based on their position in the role hierarchy of the guild.""" return self.position < other.position + + def __le__(self, other: Role) -> bool: + """Compares the roles based on their position in the role hierarchy of the guild.""" + return self.position <= other.position -- cgit v1.2.3