diff --git a/django_lostplaces/lostplaces/migrations/0002_reomve_vouchers.py b/django_lostplaces/lostplaces/migrations/0002_reomve_vouchers.py new file mode 100644 index 0000000..76a1aaf --- /dev/null +++ b/django_lostplaces/lostplaces/migrations/0002_reomve_vouchers.py @@ -0,0 +1,22 @@ +# Generated by Django 3.1.1 on 2020-10-04 19:37 +# Edited by reverend + +import datetime +from django.db import migrations, models +import django.utils.timezone +from django.utils.timezone import utc + +class Migration(migrations.Migration): + + dependencies = [ + ('lostplaces', '0001_initial'), + ] + + operations = [ + migrations.DeleteModel( + name='Voucher' + ), + migrations.DeleteModel( + name='Expireable' + ) + ] diff --git a/django_lostplaces/lostplaces/migrations/0003_voucher.py b/django_lostplaces/lostplaces/migrations/0003_voucher.py new file mode 100644 index 0000000..0fb7125 --- /dev/null +++ b/django_lostplaces/lostplaces/migrations/0003_voucher.py @@ -0,0 +1,25 @@ +# Generated by Django 3.1.1 on 2020-10-04 19:52 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('lostplaces', '0002_reomve_vouchers'), + ] + + operations = [ + migrations.CreateModel( + name='Voucher', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('created_when', models.DateTimeField(auto_now_add=True)), + ('expires_when', models.DateTimeField()), + ('code', models.CharField(max_length=30, unique=True)), + ], + options={ + 'abstract': False, + }, + ), + ] diff --git a/django_lostplaces/lostplaces/models/abstract_models.py b/django_lostplaces/lostplaces/models/abstract_models.py index c95ce61..ba4be73 100644 --- a/django_lostplaces/lostplaces/models/abstract_models.py +++ b/django_lostplaces/lostplaces/models/abstract_models.py @@ -1,4 +1,5 @@ +from django.utils import timezone from django.db import models from django.core.validators import MaxValueValidator, MinValueValidator @@ -55,7 +56,14 @@ class Submittable(models.Model): class Expireable(models.Model): """ - Base class for things that can expire, i.e. VouchersAv + Base class for things that can expire, i.e. Vouchers """ + class Meta: + abstract = True + created_when = models.DateTimeField(auto_now_add=True) - expires_when = models.DateTimeField() \ No newline at end of file + expires_when = models.DateTimeField() + + @property + def is_expired(self): + return timezone.now() > self.expires_when \ No newline at end of file