coding utf-8 from django db import models from utils configile import

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#coding=utf-8
from django.db import models
from utils.configile import Config
import datetime
import pickle
from utils import mptt
config = Config().get_data()
class Tags(models.Model):
name = models.CharField(verbose_name="Название тега", max_length=50)
weight = models.IntegerField(verbose_name="Вес тега", default=0)
def __unicode__(self):
return self.name
class Meta():
verbose_name = "тег"
verbose_name_plural = "Теги"
class Cities(models.Model):
parent = models.ForeignKey("self", verbose_name="Родитель", related_name='child_set', blank=True, null=True)
location_name = models.CharField(verbose_name="Название местности", max_length=50)
lft = models.PositiveIntegerField(editable=False, blank=True, null=True)
rght = models.PositiveIntegerField(editable=False, blank=True, null=True)
tree_id = models.PositiveIntegerField(editable=False, blank=True, null=True)
level = models.PositiveIntegerField(editable=False, blank=True, null=True)
# TODO: расширить интерфейс админки для таблицы City, сделав автозаполнение при вводе
class Meta():
verbose_name = "город"
verbose_name_plural = "Города"
def __unicode__(self):
return "--"*self.level + " " + self.location_name
mptt.register(Cities)
class Geos(models.Model):
#map
longtitude = models.FloatField(verbose_name="Долгота", blank=True, null=True)
latitude = models.FloatField(verbose_name="Широта", blank=True, null=True)
address = models.CharField(verbose_name="Адрес", max_length=255, blank=True, null=False)
extended_address = models.CharField(verbose_name="Расширеный адрес", max_length=255, blank=True, null=False)
district = models.CharField(verbose_name="Район", max_length=50, blank=True, null=False)
postal_code = models.IntegerField(verbose_name="Почтовый код", blank=True, null=True)
class hCards(models.Model):
name = models.CharField(verbose_name="Имя", max_length=255)
nickname = models.CharField(verbose_name="Ник", max_length=50, blank=True, null=False)
email = models.EmailField(verbose_name="E-mail")
phone = models.CharField(verbose_name="Телефон", max_length=50, blank=True, null=False)
geo = models.ForeignKey(Geos, verbose_name="Месторасположение", blank=True, null=True)
photo = models.ImageField(upload_to="hcard/photos/%Y/%m/%d", verbose_name="Изображение", blank=True, null=True)
bday = models.DateField(verbose_name="Дата рождения", blank=True, null=True)
#org
# TODO: для выборки объектов нужных типа создать models.Manager
# http://docs.djangoproject.com/en/dev/topics/db/managers/
class Objects(models.Model):
author = models.IntegerField(verbose_name="Автор", blank=True, null=True)
# group
type = models.PositiveSmallIntegerField(verbose_name="Тип объекта", choices=config['general']['object_type'])
name = models.CharField(verbose_name="Название", max_length=255)
# TODO: рассмотреть, стоит ли делать для поле description поле is_safe для вывода в шбалоне
description = models.TextField(verbose_name="Описание", blank=True, null=True)
tags = models.ManyToManyField(Tags, verbose_name="Теги", blank=True, null=True)
locality = models.OneToOneField(Cities, verbose_name="Город", blank=True, null=True)
geo = models.ForeignKey(Geos, verbose_name="Месторасположение", blank=True, null=True)
picture = models.ImageField(upload_to="pictures/%Y/%m/%d", verbose_name="Изображение", blank=True, null=True)
# file: to get backward relationship with File, use object.file_set.all()
# rate
# TODO: рассмотреть вопрос о таблице visits
status = models.PositiveSmallIntegerField(verbose_name="Статус объекта", choices=config['general']['status'], default=0)
created = models.DateTimeField(verbose_name="Дата создания объекта", auto_now_add=True, editable=False)
updated = models.DateTimeField(verbose_name="Дата обновления объекта", auto_now=True, editable=False)
active_from = models.DateTimeField(verbose_name="Актуален с", default=datetime.datetime.now())
active_to = models.DateTimeField(verbose_name="Актуален до", blank=True, null=True)
dump = models.TextField(verbose_name="Кэш объекта", editable=False)
class Meta():
verbose_name = "объект"
verbose_name_plural = "Объекты"
def __unicode__(self):
type = ''
for choice in config['general']['object_type']:
if int(self.type) == int(choice[0]):
type = choice[1]
return "%s %s: %s (%s)" % (type, self.id, self.name, self.author)
class Files(models.Model):
o = models.ForeignKey(Objects, verbose_name="Связанный объект")
file = models.FileField(upload_to="files/%Y/%m/%d", verbose_name="Файл")
type = models.PositiveSmallIntegerField(verbose_name="Тип файла", choices=config['general']['file_type'])
filename = models.CharField(verbose_name="Имя файла", blank=True, null=False, max_length=255)
timestamp = models.DateTimeField(verbose_name="Дата создания файла", editable=False, auto_now_add=True)
class Meta():
verbose_name = "файл"
verbose_name_plural = "Файлы"
def __unicode__(self):
return self.filename
class Announcments(models.Model):
o = models.ForeignKey(Objects, verbose_name = "Объект")
type = models.PositiveSmallIntegerField(verbose_name="Категория объявления", choices=config['general']['announcment_type'])
deal_type = models.PositiveSmallIntegerField(verbose_name="Категория объявления", choices=config['general']['deal_type'])
price = models.IntegerField(verbose_name="Цена")
contact = models.OneToOneField(hCards, verbose_name="Контактное лицо")
class Meta():
verbose_name = "обяъвление"
verbose_name_plural = "Объявления"
#===============================================================================
# class Visits(models.Model):
# o = models.ForeignKey(Object, verbose_name = "Объект")
# count = models.IntegerField(verbose_name="Кол-во просмотров", editable=False, default=0)
#===============================================================================