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.
 
 
 
 
 
 

67 lines
2.5 KiB

# -*- 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
class Country(TranslatableModel):
"""
Create Country model
Uses hvad.TranslatableModel which is child of django.db.models class
"""
try:
flags = [str(item.id) for item in Service.objects.all()]
except:
flags = []
#max = sorted(ids)[-1]
#for i in range(max):
# flags.append(str(i))
services = BitField(flags=flags)
REGIONS =('europa', 'asia', 'america', 'africa')
url = models.SlugField(unique=True)
capital = models.ForeignKey(City,blank=True, null=True, on_delete=models.PROTECT, related_name='capital')
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)
big_cities = models.ManyToManyField(City, blank=True, null=True, related_name='cities')
language = models.ManyToManyField(Language, blank=True, null=True)
currency = models.ManyToManyField(Currency, 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))