/pexp/models.py

https://bitbucket.org/bconstantin/django_polymorphic/ · Python · 49 lines · 39 code · 7 blank · 3 comment · 4 complexity · 6126a0e4610e5ad628c5428d6892f72c MD5 · raw file

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