Making expireable a abstract model
This commit is contained in:
parent
76b514e1e6
commit
cfbe54a4e5
@ -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'
|
||||||
|
)
|
||||||
|
]
|
25
django_lostplaces/lostplaces/migrations/0003_voucher.py
Normal file
25
django_lostplaces/lostplaces/migrations/0003_voucher.py
Normal file
@ -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,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
@ -1,4 +1,5 @@
|
|||||||
|
|
||||||
|
from django.utils import timezone
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.core.validators import MaxValueValidator, MinValueValidator
|
from django.core.validators import MaxValueValidator, MinValueValidator
|
||||||
|
|
||||||
@ -55,7 +56,14 @@ class Submittable(models.Model):
|
|||||||
|
|
||||||
class Expireable(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)
|
created_when = models.DateTimeField(auto_now_add=True)
|
||||||
expires_when = models.DateTimeField()
|
expires_when = models.DateTimeField()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_expired(self):
|
||||||
|
return timezone.now() > self.expires_when
|
Loading…
Reference in New Issue
Block a user