/pexp/models.py
Python | 49 lines | 39 code | 7 blank | 3 comment | 5 complexity | 6126a0e4610e5ad628c5428d6892f72c MD5 | raw file
1# -*- coding: utf-8 -*- 2 3from django.db import models 4 5from polymorphic import PolymorphicModel, PolymorphicManager, PolymorphicQuerySet 6from polymorphic.showfields import ShowFieldContent, ShowFieldType, ShowFieldTypeAndContent 7 8class Project(ShowFieldContent, PolymorphicModel): 9 topic = models.CharField(max_length=30) 10class ArtProject(Project): 11 artist = models.CharField(max_length=30) 12class ResearchProject(Project): 13 supervisor = models.CharField(max_length=30) 14 15class ModelA(ShowFieldTypeAndContent, PolymorphicModel): 16 field1 = models.CharField(max_length=10) 17class ModelB(ModelA): 18 field2 = models.CharField(max_length=10) 19class ModelC(ModelB): 20 field3 = models.CharField(max_length=10) 21 22class nModelA(models.Model): 23 field1 = models.CharField(max_length=10) 24class nModelB(nModelA): 25 field2 = models.CharField(max_length=10) 26class nModelC(nModelB): 27 field3 = models.CharField(max_length=10) 28 29# for Django 1.2+, test models with same names in different apps 30# (the other models with identical names are in polymorphic/tests.py) 31from django import VERSION as django_VERSION 32if not (django_VERSION[0]<=1 and django_VERSION[1]<=1): 33 class Model2A(PolymorphicModel): 34 field1 = models.CharField(max_length=10) 35 class Model2B(Model2A): 36 field2 = models.CharField(max_length=10) 37 class Model2C(Model2B): 38 field3 = models.CharField(max_length=10) 39 40try: from polymorphic.test_tools import UUIDField 41except: pass 42if 'UUIDField' in globals(): 43 class UUIDModelA(ShowFieldTypeAndContent, PolymorphicModel): 44 uuid_primary_key = UUIDField(primary_key = True) 45 field1 = models.CharField(max_length=10) 46 class UUIDModelB(UUIDModelA): 47 field2 = models.CharField(max_length=10) 48 class UUIDModelC(UUIDModelB): 49 field3 = models.CharField(max_length=10)