make baseticket inherit directly from uuidmodel and createdupdatedmodel

This commit is contained in:
Thomas Steen Rasmussen 2017-08-19 21:11:07 +02:00
parent 086578d3b8
commit 89aa6bfa22
2 changed files with 94 additions and 4 deletions

View file

@ -0,0 +1,89 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-08-19 19:09
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
import uuid
class Migration(migrations.Migration):
dependencies = [
('tickets', '0004_auto_20170818_1303'),
]
operations = [
migrations.RemoveField(
model_name='baseticket',
name='id',
),
migrations.RemoveField(
model_name='discountticket',
name='created',
),
migrations.RemoveField(
model_name='discountticket',
name='updated',
),
migrations.RemoveField(
model_name='discountticket',
name='uuid',
),
migrations.RemoveField(
model_name='shopticket',
name='created',
),
migrations.RemoveField(
model_name='shopticket',
name='updated',
),
migrations.RemoveField(
model_name='shopticket',
name='uuid',
),
migrations.RemoveField(
model_name='sponsorticket',
name='created',
),
migrations.RemoveField(
model_name='sponsorticket',
name='updated',
),
migrations.RemoveField(
model_name='sponsorticket',
name='uuid',
),
migrations.AddField(
model_name='baseticket',
name='created',
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now),
preserve_default=False,
),
migrations.AddField(
model_name='baseticket',
name='updated',
field=models.DateTimeField(auto_now=True),
),
migrations.AddField(
model_name='baseticket',
name='uuid',
field=models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False),
),
migrations.AlterField(
model_name='discountticket',
name='baseticket_ptr',
field=models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='tickets.BaseTicket'),
),
migrations.AlterField(
model_name='shopticket',
name='baseticket_ptr',
field=models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='tickets.BaseTicket'),
),
migrations.AlterField(
model_name='sponsorticket',
name='baseticket_ptr',
field=models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='tickets.BaseTicket'),
),
]

View file

@ -27,7 +27,7 @@ class TicketType(CreatedUpdatedModel, UUIDModel):
return '{} ({})'.format(self.name, self.camp.title) return '{} ({})'.format(self.name, self.camp.title)
class BaseTicket(models.Model): class BaseTicket(CreatedUpdatedModel, UUIDModel):
qrcode_base64 = models.TextField(null=True, blank=True) qrcode_base64 = models.TextField(null=True, blank=True)
ticket_type = models.ForeignKey('TicketType') ticket_type = models.ForeignKey('TicketType')
checked_in = models.BooleanField(default=False) checked_in = models.BooleanField(default=False)
@ -67,14 +67,14 @@ class BaseTicket(models.Model):
) )
class SponsorTicket(BaseTicket, CreatedUpdatedModel, UUIDModel): class SponsorTicket(BaseTicket):
sponsor = models.ForeignKey('sponsors.Sponsor') sponsor = models.ForeignKey('sponsors.Sponsor')
def __str__(self): def __str__(self):
return 'SponsorTicket: {}'.format(self.pk) return 'SponsorTicket: {}'.format(self.pk)
class DiscountTicket(BaseTicket, CreatedUpdatedModel, UUIDModel): class DiscountTicket(BaseTicket):
price = models.IntegerField( price = models.IntegerField(
help_text=_('Price of the discounted ticket (in DKK, including VAT).') help_text=_('Price of the discounted ticket (in DKK, including VAT).')
) )
@ -83,7 +83,7 @@ class DiscountTicket(BaseTicket, CreatedUpdatedModel, UUIDModel):
return 'DiscountTicket: {}'.format(self.pk) return 'DiscountTicket: {}'.format(self.pk)
class ShopTicket(BaseTicket, CreatedUpdatedModel, UUIDModel): class ShopTicket(BaseTicket):
order = models.ForeignKey('shop.Order', related_name='shoptickets') order = models.ForeignKey('shop.Order', related_name='shoptickets')
product = models.ForeignKey('shop.Product') product = models.ForeignKey('shop.Product')
@ -125,3 +125,4 @@ class ShopTicket(BaseTicket, CreatedUpdatedModel, UUIDModel):
def get_absolute_url(self): def get_absolute_url(self):
return str(reverse_lazy('shop:ticket_detail', kwargs={'pk': self.pk})) return str(reverse_lazy('shop:ticket_detail', kwargs={'pk': self.pk}))