File: models.py

package info (click to toggle)
django-polymorphic 0.6-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 436 kB
  • ctags: 586
  • sloc: python: 2,208; makefile: 142
file content (72 lines) | stat: -rw-r--r-- 2,364 bytes parent folder | download
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
# -*- coding: utf-8 -*-

from django.db import models

from polymorphic import PolymorphicModel, PolymorphicManager, PolymorphicQuerySet
from polymorphic.showfields import ShowFieldContent, ShowFieldType, ShowFieldTypeAndContent

class Project(ShowFieldContent, PolymorphicModel):
    topic = models.CharField(max_length=30)
class ArtProject(Project):
    artist = models.CharField(max_length=30)
class ResearchProject(Project):
    supervisor = models.CharField(max_length=30)

class ModelA(ShowFieldTypeAndContent, PolymorphicModel):
    field1 = models.CharField(max_length=10)
class ModelB(ModelA):
    field2 = models.CharField(max_length=10)
class ModelC(ModelB):
    field3 = models.CharField(max_length=10)

class nModelA(models.Model):
    field1 = models.CharField(max_length=10)
class nModelB(nModelA):
    field2 = models.CharField(max_length=10)
class nModelC(nModelB):
    field3 = models.CharField(max_length=10)

# for Django 1.2+, test models with same names in different apps
# (the other models with identical names are in polymorphic/tests.py)
from django import VERSION as django_VERSION
if not (django_VERSION[0]<=1 and django_VERSION[1]<=1):
    class Model2A(PolymorphicModel):
        field1 = models.CharField(max_length=10)
    class Model2B(Model2A):
        field2 = models.CharField(max_length=10)
    class Model2C(Model2B):
        field3 = models.CharField(max_length=10)

try: from polymorphic.test_tools  import UUIDField
except: pass
if 'UUIDField' in globals():
    class UUIDModelA(ShowFieldTypeAndContent, PolymorphicModel):
        uuid_primary_key = UUIDField(primary_key = True)
        field1 = models.CharField(max_length=10)
    class UUIDModelB(UUIDModelA):
        field2 = models.CharField(max_length=10)
    class UUIDModelC(UUIDModelB):
        field3 = models.CharField(max_length=10)

class ProxyBase(PolymorphicModel):
    title = models.CharField(max_length=200)

    def __unicode__(self):
        return u"<ProxyBase[type={0}]: {1}>".format(self.polymorphic_ctype, self.title)

    class Meta:
        ordering = ('title',)

class ProxyA(ProxyBase):
    class Meta:
        proxy = True

    def __unicode__(self):
        return u"<ProxyA: {0}>".format(self.title)

class ProxyB(ProxyBase):
    class Meta:
        proxy = True

    def __unicode__(self):
        return u"<ProxyB: {0}>".format(self.title)