diff options
Diffstat (limited to '')
| -rw-r--r-- | api/migrations/0004_role.py | 23 | ||||
| -rw-r--r-- | api/models.py | 43 | 
2 files changed, 65 insertions, 1 deletions
| diff --git a/api/migrations/0004_role.py b/api/migrations/0004_role.py new file mode 100644 index 00000000..0a6b6c43 --- /dev/null +++ b/api/migrations/0004_role.py @@ -0,0 +1,23 @@ +# Generated by Django 2.1 on 2018-09-01 19:54 + +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + +    dependencies = [ +        ('api', '0003_offtopicchannelname'), +    ] + +    operations = [ +        migrations.CreateModel( +            name='Role', +            fields=[ +                ('id', models.BigIntegerField(help_text="The role's ID, taken from Discord.", primary_key=True, serialize=False, validators=[django.core.validators.MinValueValidator(limit_value=0, message='Role IDs cannot be negative.')])), +                ('name', models.CharField(help_text="The role's name, taken from Discord.", max_length=100)), +                ('colour', models.IntegerField(help_text='The integer value of the colour of this role from Discord.', validators=[django.core.validators.MinValueValidator(limit_value=0, message='Colour hex cannot be negative.')])), +                ('permissions', models.IntegerField(help_text='The integer value of the permission bitset of this role from Discord.', validators=[django.core.validators.MinValueValidator(limit_value=0, message='Role permissions cannot be negative.'), django.core.validators.MaxValueValidator(limit_value=8589934592, message='Role permission bitset exceeds value of having all permissions')])), +            ], +        ), +    ] diff --git a/api/models.py b/api/models.py index 7f4175af..6d7af764 100644 --- a/api/models.py +++ b/api/models.py @@ -1,4 +1,4 @@ -from django.core.validators import RegexValidator +from django.core.validators import MaxValueValidator, MinValueValidator, RegexValidator  from django.db import models @@ -23,3 +23,44 @@ class SnakeName(models.Model):      name = models.CharField(primary_key=True, max_length=100)      scientific = models.CharField(max_length=150) + + +class Role(models.Model): +    """A role on our Discord server.""" + +    id = models.BigIntegerField( +        primary_key=True, +        validators=( +            MinValueValidator( +                limit_value=0, +                message="Role IDs cannot be negative." +            ), +        ), +        help_text="The role's ID, taken from Discord." +    ) +    name = models.CharField( +        max_length=100, +        help_text="The role's name, taken from Discord." +    ) +    colour = models.IntegerField( +        validators=( +            MinValueValidator( +                limit_value=0, +                message="Colour hex cannot be negative." +            ), +        ), +        help_text="The integer value of the colour of this role from Discord." +    ) +    permissions = models.IntegerField( +        validators=( +            MinValueValidator( +                limit_value=0, +                message="Role permissions cannot be negative." +            ), +            MaxValueValidator( +                limit_value=2 << 32, +                message="Role permission bitset exceeds value of having all permissions" +            ) +        ), +        help_text="The integer value of the permission bitset of this role from Discord." +    ) | 
