You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
2.0 KiB
61 lines
2.0 KiB
# -*- coding: utf-8 -*-
|
|
from django.db import models
|
|
from django.db.models.signals import post_save, pre_save
|
|
from hvad.models import TranslatableModel, TranslatedFields, TranslationManager
|
|
from bitfield import BitField
|
|
# models
|
|
from directories.models import Iata
|
|
from service.models import Service
|
|
# custom functions
|
|
from functions.db import db_table_exists
|
|
from functions.signal_handlers import post_save_handler
|
|
from functions.models_methods import ExpoManager
|
|
|
|
#check if table exist and create flags if true
|
|
flags = [str(item.id) for item in Service.objects.all()] if db_table_exists('service_service') else []
|
|
|
|
|
|
|
|
|
|
class City(TranslatableModel):
|
|
"""
|
|
Create City model
|
|
|
|
Uses hvad.TranslatableModel which is child of django.db.models class
|
|
|
|
"""
|
|
objects = ExpoManager()
|
|
|
|
services = BitField(flags=flags)
|
|
|
|
url = models.SlugField(unique=True)
|
|
#relations
|
|
country = models.ForeignKey('country.Country', null=True, on_delete=models.PROTECT, related_name='cities')
|
|
code_IATA = models.ForeignKey(Iata, blank=True, null=True)
|
|
|
|
population = models.PositiveIntegerField(blank=True, null=True)
|
|
phone_code = models.PositiveIntegerField(blank=True, null=True)
|
|
#translated fields
|
|
translations = TranslatedFields(
|
|
name = models.CharField(max_length=50),
|
|
region = models.CharField(max_length=255),
|
|
transport = models.TextField(blank=True),
|
|
description = models.TextField(blank=True),
|
|
famous_places = models.TextField(blank=True),
|
|
shoping = models.TextField(blank=True),
|
|
#-----meta
|
|
title = models.CharField(max_length=255),
|
|
descriptions = models.CharField(max_length=255),
|
|
keywords = models.CharField(max_length=255),
|
|
)
|
|
# fields saves information about creating and changing model
|
|
created = models.DateTimeField(auto_now_add=True)
|
|
modified = models.DateTimeField(auto_now=True)
|
|
|
|
def __unicode__(self):
|
|
return self.lazy_translation_getter('name', self.pk)
|
|
|
|
|
|
|
|
|
|
post_save.connect(post_save_handler, sender=City)
|
|
|