JourneyJoker/frontend/models.py

60 lines
1.7 KiB
Python
Raw Normal View History

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
from django.contrib.auth import get_user_model
2021-03-01 09:56:10 +00:00
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)()
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)
])
language = LanguageField()
2021-03-22 17:42:07 +00:00
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