Abtract classes

This commit is contained in:
reverend 2020-09-12 12:24:27 +02:00
parent 21124ec2ad
commit 3780aa6cf1

View File

@ -20,6 +20,31 @@ from taggit.managers import TaggableManager
# Create your models here. # Create your models here.
class Taggable(models.Model):
class Meta:
abstract = True
tags = TaggableManager(blank=True)
class MapablePoint(models.Model):
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 Explorer(models.Model): class Explorer(models.Model):
""" """
@ -62,12 +87,11 @@ class Voucher(models.Model):
return "Voucher " + str(self.code) return "Voucher " + str(self.code)
class Place (models.Model): class Place(Taggable, MapablePoint):
""" """
Place defines a lost place (location, name, description etc.). Place defines a lost place (location, name, description etc.).
""" """
name = models.CharField(max_length=50)
submitted_when = models.DateTimeField(auto_now_add=True, null=True) submitted_when = models.DateTimeField(auto_now_add=True, null=True)
submitted_by = models.ForeignKey( submitted_by = models.ForeignKey(
Explorer, Explorer,
@ -77,22 +101,8 @@ class Place (models.Model):
related_name='places' related_name='places'
) )
location = models.CharField(max_length=50) location = models.CharField(max_length=50)
latitude = models.FloatField(
validators=[
MinValueValidator(-90),
MaxValueValidator(90)
]
)
longitude = models.FloatField(
validators=[
MinValueValidator(-180),
MaxValueValidator(180)
]
)
description = models.TextField() description = models.TextField()
tags = TaggableManager(blank=True)
def get_absolute_url(self): def get_absolute_url(self):
return reverse('place_detail', kwargs={'pk': self.pk}) return reverse('place_detail', kwargs={'pk': self.pk})