My favorites
|
Sign in
django-attributes
Generic attribute support for Django models
Project Home
Downloads
Wiki
Issues
Source
Checkout
|
Browse
|
Changes
|
r2
Source path:
svn
/
trunk
/
attributes
/
models.py
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
from django.db import models
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
class Attribute(models.Model):
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey('content_type', 'object_id')
key = models.CharField(max_length=50, db_index=True)
type = models.CharField(max_length=50)
def __init__(self, *args, **kwargs):
super(Attribute, self).__init__(*args, **kwargs)
if not self.type:
self.type = self.__class__.__name__.lower()
def __unicode__(self):
return u'%s: %s' % (self.content_object, self.key)
class IntegerAttribute(Attribute):
value = models.IntegerField()
class FloatAttribute(Attribute):
value = models.FloatField()
class StringAttribute(Attribute):
value = models.CharField(max_length=100, blank=True)
class DateRangeAttribute(Attribute):
start = models.DateField()
end = models.DateField()
def model_for_type(t):
if t == int:
return IntegerAttribute
elif t == float:
return FloatAttribute
else:
return StringAttribute
Show details
Hide details
Change log
r2
by matthias.kestenholz on Jul 23, 2008
Diff
Initial commit
Go to:
/trunk/LICENSE.txt
/trunk/attributes
/trunk/attributes/__init__.py
/trunk/attributes/managers.py
/trunk/attributes/models.py
Project members,
sign in
to write a code review
Older revisions
All revisions of this file
File info
Size: 1191 bytes, 48 lines
View raw file
Hosted by