2021-06-06 08:59:10 +00:00
|
|
|
from django.contrib.gis.db import models
|
2021-03-22 17:42:07 +00:00
|
|
|
from django.conf import settings
|
|
|
|
from django.core.validators import MaxValueValidator, MinValueValidator
|
2021-06-06 08:59:10 +00:00
|
|
|
from django.contrib.auth import get_user_model
|
2021-03-01 09:56:10 +00:00
|
|
|
|
2021-06-06 08:59:10 +00:00
|
|
|
from localauth.models import ImageMixin
|
|
|
|
|
2021-06-14 04:06:32 +00:00
|
|
|
from .fields import LanguageField
|
|
|
|
|
2021-06-06 08:59:10 +00:00
|
|
|
from django_countries.fields import CountryField
|
|
|
|
|
|
|
|
class ClassProperty(property):
|
|
|
|
def __get__(self, cls, owner):
|
|
|
|
return self.fget.__get__(None, owner)()
|
2021-03-22 17:42:07 +00:00
|
|
|
|
|
|
|
class Testimonial(models.Model):
|
|
|
|
name = models.CharField(max_length=128)
|
|
|
|
text = models.TextField()
|
|
|
|
stars = models.PositiveIntegerField(
|
|
|
|
validators=[
|
|
|
|
MaxValueValidator(5),
|
|
|
|
MinValueValidator(1)
|
|
|
|
])
|
2021-06-14 04:06:32 +00:00
|
|
|
language = LanguageField()
|
2021-03-22 17:42:07 +00:00
|
|
|
public = models.BooleanField(default=False)
|
2021-06-06 08:59:10 +00:00
|
|
|
|
|
|
|
class InspirationRegion(models.Model):
|
|
|
|
name = models.CharField(max_length=128)
|
|
|
|
is_state = models.BooleanField(default=False)
|
|
|
|
country = CountryField()
|
|
|
|
|
|
|
|
@ClassProperty
|
|
|
|
@classmethod
|
|
|
|
def country_set(cls):
|
|
|
|
return cls.objects.all().values_list("country").distinct()
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
class InspirationSponsor(ImageMixin):
|
|
|
|
user = models.ForeignKey(get_user_model(), models.SET_NULL, null=True, blank=True)
|
|
|
|
name = models.CharField(max_length=128)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
class Inspiration(ImageMixin):
|
|
|
|
title = models.CharField(max_length=256)
|
2021-06-14 12:11:45 +00:00
|
|
|
subtitle = models.CharField(max_length=256, null=True, blank=True)
|
2021-06-06 08:59:10 +00:00
|
|
|
region = models.ForeignKey(InspirationRegion, models.PROTECT)
|
|
|
|
sponsor = models.ForeignKey(InspirationSponsor, models.PROTECT)
|
|
|
|
content = models.TextField()
|
|
|
|
destination_name = models.CharField(max_length=128)
|
|
|
|
destination_coords = models.PointField()
|
|
|
|
|
|
|
|
@property
|
|
|
|
def user(self):
|
|
|
|
return self.sponsor.user
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.title
|