# -*- coding: utf-8 -*- from django.db import models from hvad.models import TranslatableModel, TranslatedFields from django.contrib.contenttypes import generic #models from directories.models import Language, Currency from city.models import City from service.models import Service #func from functions.custom_fields import EnumField from bitfield import BitField from functions.db import db_table_exists #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 Country(TranslatableModel): """ Create Country model Uses hvad.TranslatableModel which is child of django.db.models class """ services = BitField(flags=flags) REGIONS =('europa', 'asia', 'america', 'africa') url = models.SlugField(unique=True) #relations big_cities = models.ManyToManyField(City, blank=True, null=True, related_name='cities') capital = models.ForeignKey(City,blank=True, null=True, on_delete=models.PROTECT, related_name='capital') language = models.ManyToManyField(Language, blank=True, null=True) currency = models.ManyToManyField(Currency, blank=True, null=True) population = models.PositiveIntegerField(blank=True, null=True) teritory = models.PositiveIntegerField(blank=True, null=True) timezone = models.FloatField(blank=True, null=True) phone_code = models.PositiveIntegerField(blank=True, null=True) time_delivery = models.PositiveSmallIntegerField(blank=True, null=True) # region = EnumField(values=REGIONS) #fields saves information about creating and changing model created = models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now=True) #connection with FileModel by ContentType files = generic.GenericRelation('file.FileModel',content_type_field='content_type', object_id_field='object_id') #translated fields translations = TranslatedFields( name = models.CharField(max_length=30), description = models.TextField(blank=True), transport = models.TextField(blank=True), #------visa inf rules = models.TextField(blank=True), documents = models.TextField(blank=True),#pdf? consulate = models.TextField(blank=True), #-----meta data title = models.CharField(max_length=250), descriptions = models.CharField(max_length=250), keywords = models.CharField(max_length=250), ) def __unicode__(self): return self.lazy_translation_getter('name', unicode(self.pk))