Abtract classes
This commit is contained in:
		@@ -20,6 +20,31 @@ from taggit.managers import TaggableManager
 | 
			
		||||
 | 
			
		||||
# 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):
 | 
			
		||||
    """
 | 
			
		||||
@@ -62,12 +87,11 @@ class Voucher(models.Model):
 | 
			
		||||
        return "Voucher " + str(self.code)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Place (models.Model):
 | 
			
		||||
class Place(Taggable, MapablePoint):
 | 
			
		||||
    """
 | 
			
		||||
    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_by = models.ForeignKey(
 | 
			
		||||
        Explorer,
 | 
			
		||||
@@ -77,22 +101,8 @@ class Place (models.Model):
 | 
			
		||||
        related_name='places'
 | 
			
		||||
    )
 | 
			
		||||
    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()
 | 
			
		||||
 | 
			
		||||
    tags = TaggableManager(blank=True)
 | 
			
		||||
 | 
			
		||||
    def get_absolute_url(self):
 | 
			
		||||
        return reverse('place_detail', kwargs={'pk': self.pk})
 | 
			
		||||
    
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user