add used_time to BaseTicket model so we know when tickets were checked in/used

This commit is contained in:
Thomas Steen Rasmussen 2021-08-02 20:11:36 +02:00
parent a99c546e06
commit 48952c5463
4 changed files with 61 additions and 0 deletions

View file

@ -3,6 +3,7 @@ from itertools import chain
from django.contrib import messages
from django.contrib.auth.mixins import LoginRequiredMixin
from django.utils import timezone
from django.views.generic import ListView, TemplateView
from camps.mixins import CampViewMixin
@ -121,6 +122,7 @@ class ScanTicketsView(
check_in_ticket_id = request.POST.get("check_in_ticket_id")
ticket_to_check_in = _ticket_getter_by_pk(check_in_ticket_id)
ticket_to_check_in.used = True
ticket_to_check_in.used_time = timezone.now()
ticket_to_check_in.save()
messages.info(request, "Ticket checked-in!")
return ticket_to_check_in

View file

@ -0,0 +1,28 @@
# Generated by Django 3.2.5 on 2021-08-02 17:56
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("tickets", "0018_remove_shopticket_order"),
]
operations = [
migrations.AddField(
model_name="discountticket",
name="used_time",
field=models.DateTimeField(null=True),
),
migrations.AddField(
model_name="shopticket",
name="used_time",
field=models.DateTimeField(null=True),
),
migrations.AddField(
model_name="sponsorticket",
name="used_time",
field=models.DateTimeField(null=True),
),
]

View file

@ -0,0 +1,30 @@
# Generated by Django 3.2.5 on 2021-08-02 17:56
from django.db import migrations
def populate_ticket_used_when(apps, schema_editor):
ShopTicket = apps.get_model("tickets", "ShopTicket")
SponsorTicket = apps.get_model("tickets", "SponsorTicket")
DiscountTicket = apps.get_model("tickets", "DiscountTicket")
for st in ShopTicket.objects.filter(used_time__isnull=True, used=True):
st.used_when = st.updated
st.save()
for st in SponsorTicket.objects.filter(used_time__isnull=True, used=True):
st.used_when = st.updated
st.save()
for dt in DiscountTicket.objects.filter(used_time__isnull=True, used=True):
st.used_when = st.updated
st.save()
class Migration(migrations.Migration):
dependencies = [
("tickets", "0019_auto_20210802_1756"),
]
operations = [migrations.RunPython(populate_ticket_used_when)]

View file

@ -98,6 +98,7 @@ def qr_code_base64(token):
class BaseTicket(CampRelatedModel, UUIDModel):
ticket_type = models.ForeignKey("TicketType", on_delete=models.PROTECT)
used = models.BooleanField(default=False)
used_time = models.DateTimeField(null=True)
badge_handed_out = models.BooleanField(default=False)
token = models.CharField(max_length=64, blank=True)
badge_token = models.CharField(max_length=64, blank=True)