generated from bisco/codex-bootstrap
feat: add initial Django domain models
This commit is contained in:
17
backend/checkins/admin.py
Normal file
17
backend/checkins/admin.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from .models import CheckIn
|
||||
|
||||
|
||||
@admin.register(CheckIn)
|
||||
class CheckInAdmin(admin.ModelAdmin):
|
||||
list_display = ("reservation", "checked_in_at", "checked_in_by", "source", "created_at")
|
||||
list_filter = ("source", "checked_in_at", "created_at")
|
||||
search_fields = (
|
||||
"reservation__name",
|
||||
"reservation__email",
|
||||
"reservation__performance__show__title",
|
||||
"checked_in_by__username",
|
||||
"checked_in_by__email",
|
||||
)
|
||||
readonly_fields = ("created_at", "updated_at")
|
||||
54
backend/checkins/migrations/0001_initial.py
Normal file
54
backend/checkins/migrations/0001_initial.py
Normal file
@@ -0,0 +1,54 @@
|
||||
# Generated by Django 5.2.3 on 2026-04-28
|
||||
|
||||
import django.db.models.deletion
|
||||
import django.utils.timezone
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
("bookings", "0001_initial"),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name="CheckIn",
|
||||
fields=[
|
||||
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
|
||||
("checked_in_at", models.DateTimeField(default=django.utils.timezone.now)),
|
||||
(
|
||||
"source",
|
||||
models.CharField(choices=[("qr_scan", "QR scan"), ("manual", "Manual")], default="qr_scan", max_length=20),
|
||||
),
|
||||
("created_at", models.DateTimeField(auto_now_add=True)),
|
||||
("updated_at", models.DateTimeField(auto_now=True)),
|
||||
(
|
||||
"checked_in_by",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.PROTECT,
|
||||
related_name="checkins",
|
||||
to=settings.AUTH_USER_MODEL,
|
||||
),
|
||||
),
|
||||
(
|
||||
"reservation",
|
||||
models.OneToOneField(
|
||||
on_delete=django.db.models.deletion.PROTECT,
|
||||
related_name="check_in",
|
||||
to="bookings.reservation",
|
||||
),
|
||||
),
|
||||
],
|
||||
options={
|
||||
"ordering": ["-checked_in_at"],
|
||||
"indexes": [
|
||||
models.Index(fields=["checked_in_at"], name="checkins_ch_checked_761e33_idx"),
|
||||
models.Index(fields=["checked_in_by"], name="checkins_ch_checked_becaae_idx"),
|
||||
],
|
||||
},
|
||||
),
|
||||
]
|
||||
1
backend/checkins/migrations/__init__.py
Normal file
1
backend/checkins/migrations/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
@@ -1 +1,46 @@
|
||||
# Domain models will be added when check-in behavior is implemented.
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.db import models
|
||||
from django.utils import timezone
|
||||
|
||||
from bookings.models import Reservation
|
||||
|
||||
|
||||
class CheckIn(models.Model):
|
||||
class Source(models.TextChoices):
|
||||
QR_SCAN = "qr_scan", "QR scan"
|
||||
MANUAL = "manual", "Manual"
|
||||
|
||||
reservation = models.OneToOneField(
|
||||
Reservation,
|
||||
on_delete=models.PROTECT,
|
||||
related_name="check_in",
|
||||
)
|
||||
checked_in_at = models.DateTimeField(default=timezone.now)
|
||||
checked_in_by = models.ForeignKey(
|
||||
settings.AUTH_USER_MODEL,
|
||||
on_delete=models.PROTECT,
|
||||
related_name="checkins",
|
||||
)
|
||||
source = models.CharField(max_length=20, choices=Source.choices, default=Source.QR_SCAN)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ["-checked_in_at"]
|
||||
indexes = [
|
||||
models.Index(fields=["checked_in_at"]),
|
||||
models.Index(fields=["checked_in_by"]),
|
||||
]
|
||||
|
||||
def __str__(self):
|
||||
return f"Check-in for reservation {self.reservation_id}"
|
||||
|
||||
def clean(self):
|
||||
super().clean()
|
||||
if self.reservation_id and not self.reservation.is_confirmed:
|
||||
raise ValidationError({"reservation": "Only confirmed reservations can be checked in."})
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
self.full_clean()
|
||||
return super().save(*args, **kwargs)
|
||||
|
||||
Reference in New Issue
Block a user