from django.contrib.gis.db import models from django.conf import settings from django.core.validators import MaxValueValidator, MinValueValidator from django.contrib.auth import get_user_model from localauth.models import ImageMixin from .fields import LanguageField from django_countries.fields import CountryField class ClassProperty(property): def __get__(self, cls, owner): return self.fget.__get__(None, owner)() class Testimonial(models.Model): name = models.CharField(max_length=128) text = models.TextField() stars = models.PositiveIntegerField( validators=[ MaxValueValidator(5), MinValueValidator(1) ]) language = LanguageField() public = models.BooleanField(default=False) 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) 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