Change TeamMember id field to random ids
This commit is contained in:
parent
8ae99da8a1
commit
d186f048fb
|
@ -26,8 +26,9 @@ class FallbackAssignmentInline(admin.TabularInline):
|
||||||
|
|
||||||
@admin.register(TeamMember)
|
@admin.register(TeamMember)
|
||||||
class TeamMemberAdmin(admin.ModelAdmin):
|
class TeamMemberAdmin(admin.ModelAdmin):
|
||||||
fields = ["name"]
|
fields = ("id", "name")
|
||||||
list_display = ["name", "shift_count"]
|
readonly_fields = ("id",)
|
||||||
|
list_display = ("name", "shift_count")
|
||||||
inlines = (FallbackAssignmentInline,)
|
inlines = (FallbackAssignmentInline,)
|
||||||
actions = (assign_random_shifts, clear_shifts, reshuffle_shifts)
|
actions = (assign_random_shifts, clear_shifts, reshuffle_shifts)
|
||||||
|
|
||||||
|
|
|
@ -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,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
|
@ -4,11 +4,17 @@ from django.db.models import Count, Exists, OuterRef, ExpressionWrapper
|
||||||
from django.db.models.lookups import LessThan
|
from django.db.models.lookups import LessThan
|
||||||
from django.db.models.fields import DateTimeField
|
from django.db.models.fields import DateTimeField
|
||||||
import math
|
import math
|
||||||
|
import secrets
|
||||||
|
|
||||||
night_shift_query = Q(start_at__hour__gte=21) | Q(start_at__hour__lte=10)
|
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):
|
class TeamMember(models.Model):
|
||||||
|
id = models.IntegerField(default=generate_id, editable=False, primary_key=True)
|
||||||
name = models.CharField(max_length=100)
|
name = models.CharField(max_length=100)
|
||||||
fallback_shifts = models.ManyToManyField(Shift, through="FallbackAssignment")
|
fallback_shifts = models.ManyToManyField(Shift, through="FallbackAssignment")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue