class Customer models Model name models CharField max_length 255 def _

 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
class Customer(models.Model):
name = models.CharField(max_length = 255)
def __unicode__(self):
return self.name
class Admin:
pass
class CustomerPropertyType(models.Model):
class Enumerator:
def __init__(self):
self.__objs = CustomerPropertyType.objects.all().iterator()
def __call__(self):
try:
return self.__objs.next()
except StopIteration:
return None
name = models.CharField(max_length = 255)
def __unicode__(self):
return self.name
class Admin:
pass
class CustomerProperty(models.Model):
# edit_inline = models.STACKED || models.TABULAR
customer = models.ForeignKey(
Customer,
edit_inline = models.TABULAR,
num_in_admin = CustomerPropertyType.objects.count() + 1)
type = models.ForeignKey(
CustomerPropertyType,
core = True,
default = CustomerPropertyType.Enumerator())
value = models.CharField(max_length = 255, core = True, default = CustomerPropertyType.Enumerator())
def __unicode__(self):
return u"%s клиента %s (%s)" % (self.type.name, self.customer.name, self.value)