69 lines
1.7 KiB
Python
69 lines
1.7 KiB
Python
|
|
from django.utils import timezone
|
|
from django.db import models
|
|
from django.core.validators import MaxValueValidator, MinValueValidator
|
|
|
|
from taggit.managers import TaggableManager
|
|
|
|
class Taggable(models.Model):
|
|
'''
|
|
This abstract model represtens an object that is taggalble
|
|
using django-taggit
|
|
'''
|
|
class Meta:
|
|
abstract = True
|
|
|
|
tags = TaggableManager(blank=True)
|
|
|
|
class Mapable(models.Model):
|
|
'''
|
|
This abstract model class represents an object that can be
|
|
displayed on a map.
|
|
'''
|
|
class Meta:
|
|
abstract = True
|
|
|
|
name = models.CharField(max_length=50)
|
|
latitude = models.FloatField(
|
|
validators=[
|
|
MinValueValidator(-90),
|
|
MaxValueValidator(90)
|
|
]
|
|
)
|
|
longitude = models.FloatField(
|
|
validators=[
|
|
MinValueValidator(-180),
|
|
MaxValueValidator(180)
|
|
]
|
|
)
|
|
|
|
class Submittable(models.Model):
|
|
'''
|
|
This abstract model class represents an object that can be submitted by
|
|
an explorer.
|
|
'''
|
|
class Meta:
|
|
abstract = True
|
|
|
|
submitted_when = models.DateTimeField(auto_now_add=True, null=True)
|
|
submitted_by = models.ForeignKey(
|
|
'Explorer',
|
|
on_delete=models.SET_NULL,
|
|
null=True,
|
|
blank=True,
|
|
related_name='%(class)ss'
|
|
)
|
|
|
|
class Expireable(models.Model):
|
|
"""
|
|
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()
|
|
|
|
@property
|
|
def is_expired(self):
|
|
return timezone.now() > self.expires_when |