from django.contrib.gis.db import models from .features import * from localauth.models import User, Profile, LocationMixin, ImageMixin, PhoneMixin from gallery.mixins import GalleryMixin 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, GalleryMixin): 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(GalleryMixin): 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)