2021-03-24 06:43:05 +00:00
|
|
|
from django.contrib.gis.db import models
|
2021-03-01 09:56:10 +00:00
|
|
|
|
2021-04-18 06:12:15 +00:00
|
|
|
from .features import *
|
|
|
|
|
2021-04-14 05:38:52 +00:00
|
|
|
from localauth.models import User, Profile, LocationMixin, ImageMixin, PhoneMixin
|
2021-03-22 17:42:07 +00:00
|
|
|
|
|
|
|
from django_countries.fields import CountryField
|
|
|
|
|
|
|
|
class PartnerProfile(Profile):
|
2021-04-18 06:12:15 +00:00
|
|
|
@property
|
|
|
|
def roomcategory_set(self):
|
|
|
|
return RoomCategory.objects.filter(establishment__in=self.establishment_set.all())
|
2021-03-22 17:42:07 +00:00
|
|
|
|
2021-04-14 05:38:52 +00:00
|
|
|
class Establishment(LocationMixin, ImageMixin, PhoneMixin):
|
2021-03-22 17:42:07 +00:00
|
|
|
owner = models.ForeignKey(PartnerProfile, models.CASCADE)
|
2021-04-17 18:35:29 +00:00
|
|
|
name = models.CharField("Name", max_length=64)
|
|
|
|
stars = models.IntegerField("Sterne", null=True, blank=True)
|
|
|
|
superior = models.BooleanField("Superior", default=False)
|
2021-04-09 05:18:21 +00:00
|
|
|
verified = models.BooleanField(default=False)
|
2021-04-17 18:35:29 +00:00
|
|
|
active = models.BooleanField(default=True)
|
2021-04-20 06:36:59 +00:00
|
|
|
featureset = models.OneToOneField(FeatureSet, models.PROTECT, null=True, blank=True)
|
2021-04-17 18:35:29 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def user(self):
|
|
|
|
return self.owner.user
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_active(self):
|
|
|
|
return self.verified and self.active
|
|
|
|
|
2021-04-18 06:12:15 +00:00
|
|
|
@property
|
2021-04-17 18:35:29 +00:00
|
|
|
def booking_set(self):
|
|
|
|
return self.offer_set.filter(accepted=True)
|
2021-03-22 17:42:07 +00:00
|
|
|
|
2021-04-20 06:36:59 +00:00
|
|
|
@property
|
|
|
|
def offer_set(self):
|
|
|
|
querysets = []
|
|
|
|
for roomcategory in self.roomcategory_set.all():
|
|
|
|
querysets.append(roomcategory.offer_set.all())
|
|
|
|
|
|
|
|
return querysets[0].union(*querysets[1:])
|
|
|
|
|
2021-04-12 12:39:18 +00:00
|
|
|
class RoomCategory(ImageMixin):
|
2021-03-22 17:42:07 +00:00
|
|
|
establishment = models.ForeignKey(Establishment, models.CASCADE)
|
2021-04-20 06:36:59 +00:00
|
|
|
name = models.CharField("Name", max_length=64)
|
|
|
|
average_price = models.DecimalField("Durchschnittspreis / Nacht", max_digits=10, decimal_places=2)
|
|
|
|
active = models.BooleanField(default=True)
|