diff --git a/shiftregister/fallback/admin.py b/shiftregister/fallback/admin.py index cf0b11b..ac658db 100644 --- a/shiftregister/fallback/admin.py +++ b/shiftregister/fallback/admin.py @@ -26,8 +26,9 @@ class FallbackAssignmentInline(admin.TabularInline): @admin.register(TeamMember) class TeamMemberAdmin(admin.ModelAdmin): - fields = ["name"] - list_display = ["name", "shift_count"] + fields = ("id", "name") + readonly_fields = ("id",) + list_display = ("name", "shift_count") inlines = (FallbackAssignmentInline,) actions = (assign_random_shifts, clear_shifts, reshuffle_shifts) diff --git a/shiftregister/fallback/migrations/0005_alter_teammember_id.py b/shiftregister/fallback/migrations/0005_alter_teammember_id.py new file mode 100644 index 0000000..f1d30ad --- /dev/null +++ b/shiftregister/fallback/migrations/0005_alter_teammember_id.py @@ -0,0 +1,23 @@ +# Generated by Django 4.0.4 on 2023-05-13 17:28 + +from django.db import migrations, models +import shiftregister.fallback.models + + +class Migration(migrations.Migration): + dependencies = [ + ("fallback", "0004_remove_fallbackassignment_slot"), + ] + + operations = [ + migrations.AlterField( + model_name="teammember", + name="id", + field=models.IntegerField( + default=shiftregister.fallback.models.generate_id, + editable=False, + primary_key=True, + serialize=False, + ), + ), + ] diff --git a/shiftregister/fallback/models.py b/shiftregister/fallback/models.py index c0a4ac0..694ed35 100644 --- a/shiftregister/fallback/models.py +++ b/shiftregister/fallback/models.py @@ -4,11 +4,17 @@ from django.db.models import Count, Exists, OuterRef, ExpressionWrapper from django.db.models.lookups import LessThan from django.db.models.fields import DateTimeField import math +import secrets night_shift_query = Q(start_at__hour__gte=21) | Q(start_at__hour__lte=10) +def generate_id(): + return int.from_bytes(secrets.token_bytes(3)) + + class TeamMember(models.Model): + id = models.IntegerField(default=generate_id, editable=False, primary_key=True) name = models.CharField(max_length=100) fallback_shifts = models.ManyToManyField(Shift, through="FallbackAssignment")