JourneyJoker/partners/models.py
Klaus-Uwe Mitterer 81f7d6eb66 Flow improvements
Dynamic displaying of received offers
2021-04-20 08:36:59 +02:00

47 lines
No EOL
1.6 KiB
Python

from django.contrib.gis.db import models
from .features import *
from localauth.models import User, Profile, LocationMixin, ImageMixin, PhoneMixin
from django_countries.fields import CountryField
class PartnerProfile(Profile):
@property
def roomcategory_set(self):
return RoomCategory.objects.filter(establishment__in=self.establishment_set.all())
class Establishment(LocationMixin, ImageMixin, PhoneMixin):
owner = models.ForeignKey(PartnerProfile, models.CASCADE)
name = models.CharField("Name", max_length=64)
stars = models.IntegerField("Sterne", null=True, blank=True)
superior = models.BooleanField("Superior", default=False)
verified = models.BooleanField(default=False)
active = models.BooleanField(default=True)
featureset = models.OneToOneField(FeatureSet, models.PROTECT, null=True, blank=True)
@property
def user(self):
return self.owner.user
@property
def is_active(self):
return self.verified and self.active
@property
def booking_set(self):
return self.offer_set.filter(accepted=True)
@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:])
class RoomCategory(ImageMixin):
establishment = models.ForeignKey(Establishment, models.CASCADE)
name = models.CharField("Name", max_length=64)
average_price = models.DecimalField("Durchschnittspreis / Nacht", max_digits=10, decimal_places=2)
active = models.BooleanField(default=True)