2
0
Fork 0

Change TeamMember id field to random ids

This commit is contained in:
Luca 2023-05-13 19:32:23 +02:00
parent 8ae99da8a1
commit d186f048fb
3 changed files with 32 additions and 2 deletions

View File

@ -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)

View File

@ -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,
),
),
]

View File

@ -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")