backend/passfinder/events/models.py

168 lines
5.4 KiB
Python
Raw Normal View History

2023-05-19 20:14:44 +03:00
from django.contrib.postgres.fields import ArrayField
2023-05-18 22:43:35 +03:00
from django.db import models
from polymorphic.models import PolymorphicModel
2023-05-20 16:47:08 +03:00
from passfinder.utils.choices import count_max_length
2023-05-18 22:43:35 +03:00
class OIDModel(models.Model):
2023-05-20 16:47:08 +03:00
oid = models.CharField(primary_key=True, max_length=24, unique=True)
2023-05-18 22:43:35 +03:00
class Meta:
abstract = True
class Region(OIDModel):
2023-05-20 16:47:08 +03:00
city = models.ForeignKey(
"City", null=True, related_name="regions", on_delete=models.CASCADE
)
2023-05-18 22:43:35 +03:00
title = models.CharField(max_length=250)
2023-05-20 16:47:08 +03:00
description = models.TextField()
description_title = models.CharField(max_length=250)
description_short = models.CharField(max_length=500)
url = models.URLField()
showcase_cards = models.JSONField(null=True)
2023-05-18 22:43:35 +03:00
2023-05-19 20:14:44 +03:00
def __str__(self):
return self.title
2023-05-18 22:43:35 +03:00
2023-05-20 16:47:08 +03:00
class RegionMedia(OIDModel):
file = models.FileField(upload_to="uploads/")
type = models.CharField(max_length=200)
region = models.ForeignKey("Region", related_name="media", on_delete=models.CASCADE)
2023-05-19 20:14:44 +03:00
2023-05-18 22:43:35 +03:00
class City(OIDModel):
title = models.CharField(max_length=250)
region = models.ForeignKey(
"Region", related_name="cities", null=True, on_delete=models.SET_NULL
)
2023-05-21 20:46:07 +03:00
lon = models.FloatField(default=0, db_index=True)
lat = models.FloatField(default=0, db_index=True)
@property
def location(self):
return [self.lon, self.lat]
2023-05-18 22:43:35 +03:00
2023-05-19 20:14:44 +03:00
def __str__(self):
return self.title
class Place(OIDModel):
2023-05-20 16:47:08 +03:00
address = models.CharField(max_length=250, null=True, blank=True)
2023-05-19 20:14:44 +03:00
parser_source = models.CharField(max_length=250)
city = models.ForeignKey(
"City", related_name="places", null=True, on_delete=models.SET_NULL
)
2023-05-20 16:47:08 +03:00
region = models.ForeignKey(
"Region", related_name="places", null=True, on_delete=models.SET_NULL
)
title = models.CharField(max_length=250)
2023-05-19 20:14:44 +03:00
description = models.TextField()
2023-05-21 20:46:07 +03:00
lon = models.FloatField(default=0, db_index=True)
lat = models.FloatField(default=0, db_index=True)
2023-05-20 16:47:08 +03:00
sites = ArrayField(models.CharField(max_length=250), null=True)
phones = ArrayField(models.CharField(max_length=250), null=True)
2023-05-19 20:14:44 +03:00
working_time = models.JSONField(null=True)
2023-05-21 20:46:07 +03:00
@property
def location(self):
return [self.lon, self.lat]
2023-05-18 22:43:35 +03:00
class Tag(OIDModel):
name = models.CharField(max_length=250)
2023-05-19 20:14:44 +03:00
def __str__(self):
return self.name
2023-05-18 22:43:35 +03:00
2023-05-19 20:14:44 +03:00
class BasePoint(OIDModel, PolymorphicModel):
2023-05-18 22:43:35 +03:00
title = models.CharField(max_length=250)
2023-05-20 16:47:08 +03:00
parser_source = models.CharField(max_length=250, null=True, blank=True)
2023-05-18 22:43:35 +03:00
description = models.TextField()
city = models.ForeignKey(
2023-05-19 20:14:44 +03:00
"City", related_name="points", null=True, on_delete=models.SET_NULL
2023-05-18 22:43:35 +03:00
)
region = models.ForeignKey(
"Region", related_name="points", null=True, on_delete=models.SET_NULL
)
2023-05-20 16:47:08 +03:00
place = models.ForeignKey(
"Place", related_name="points", null=True, on_delete=models.SET_NULL
)
sort = models.IntegerField(default=0)
2023-05-21 20:46:07 +03:00
lon = models.FloatField(default=0, db_index=True)
lat = models.FloatField(default=0, db_index=True)
2023-05-20 16:47:08 +03:00
can_buy = models.BooleanField(default=True)
priority = models.BooleanField(default=False)
2023-05-19 20:14:44 +03:00
2023-05-21 20:46:07 +03:00
@property
def location(self):
return [self.lon, self.lat]
@property
def icon(self):
# TODO: change to icon/first image
return "https://akarpov.ru/media/uploads/files/qMO4dDfIXP.webp"
2023-05-19 20:14:44 +03:00
def __str__(self):
return self.title
class PointMedia(OIDModel):
file = models.FileField(upload_to="uploads/")
type = models.CharField(max_length=200)
point = models.ForeignKey(
"BasePoint", related_name="media", on_delete=models.CASCADE
)
class Event(BasePoint):
2023-05-20 16:47:08 +03:00
class EventType(models.TextChoices):
yarmarka = "fair", "ярмарка"
bulvar = "boulevard", "бульвар"
dostoprimechatelnost = "attraction", "достопримечательность"
excursii = "excursion", "экскурсия"
teatr = "theatre", "театр"
museum = "museum", "музей"
kino = "movie", "кино"
concert = "concert", "концерт"
spektatli = "plays", "спектакли"
payment_method = models.CharField(max_length=250, null=True, blank=True)
type = models.CharField(
db_index=True,
choices=EventType.choices,
max_length=count_max_length(EventType),
)
age = models.CharField(
"Возрастное ограничение", max_length=50, blank=True, null=True
)
booking_link = models.URLField(null=True, blank=True)
discover_moscow_link = models.URLField(null=True, blank=True)
2023-05-19 20:14:44 +03:00
duration = models.IntegerField(blank=True, null=True)
ticket_price = models.IntegerField(blank=True, null=True)
schedule = models.JSONField(null=True)
class Hotel(BasePoint):
address = models.CharField(max_length=250)
rooms = models.JSONField(null=True)
email = models.CharField(max_length=250)
stars = models.IntegerField(null=True)
class HotelPhone(models.Model):
hotel = models.ForeignKey("Hotel", related_name="phones", on_delete=models.CASCADE)
name = models.CharField(max_length=50)
number = models.CharField(max_length=18)
class Restaurant(BasePoint):
2023-05-21 10:08:30 +03:00
address = models.CharField(max_length=250)
bill = models.IntegerField(null=True)
can_reserve = models.BooleanField(default=True)
avg_time_visit = models.IntegerField(null=True)
2023-05-19 20:14:44 +03:00
working_time = models.JSONField(null=True)
2023-05-21 10:08:30 +03:00
phones = ArrayField(models.CharField(max_length=18), null=True)