PageRenderTime 26ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/regressiontests/multiple_database/models.py

https://code.google.com/p/mango-py/
Python | 76 lines | 55 code | 17 blank | 4 comment | 0 complexity | 5ab36f4cb960804719990929349d49b1 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. from django.conf import settings
  2. from django.contrib.auth.models import User
  3. from django.contrib.contenttypes.models import ContentType
  4. from django.contrib.contenttypes import generic
  5. from django.db import models
  6. class Review(models.Model):
  7. source = models.CharField(max_length=100)
  8. content_type = models.ForeignKey(ContentType)
  9. object_id = models.PositiveIntegerField()
  10. content_object = generic.GenericForeignKey()
  11. def __unicode__(self):
  12. return self.source
  13. class Meta:
  14. ordering = ('source',)
  15. class PersonManager(models.Manager):
  16. def get_by_natural_key(self, name):
  17. return self.get(name=name)
  18. class Person(models.Model):
  19. objects = PersonManager()
  20. name = models.CharField(max_length=100)
  21. def __unicode__(self):
  22. return self.name
  23. class Meta:
  24. ordering = ('name',)
  25. # This book manager doesn't do anything interesting; it just
  26. # exists to strip out the 'extra_arg' argument to certain
  27. # calls. This argument is used to establish that the BookManager
  28. # is actually getting used when it should be.
  29. class BookManager(models.Manager):
  30. def create(self, *args, **kwargs):
  31. kwargs.pop('extra_arg', None)
  32. return super(BookManager, self).create(*args, **kwargs)
  33. def get_or_create(self, *args, **kwargs):
  34. kwargs.pop('extra_arg', None)
  35. return super(BookManager, self).get_or_create(*args, **kwargs)
  36. class Book(models.Model):
  37. objects = BookManager()
  38. title = models.CharField(max_length=100)
  39. published = models.DateField()
  40. authors = models.ManyToManyField(Person)
  41. editor = models.ForeignKey(Person, null=True, related_name='edited')
  42. reviews = generic.GenericRelation(Review)
  43. pages = models.IntegerField(default=100)
  44. def __unicode__(self):
  45. return self.title
  46. class Meta:
  47. ordering = ('title',)
  48. class Pet(models.Model):
  49. name = models.CharField(max_length=100)
  50. owner = models.ForeignKey(Person)
  51. def __unicode__(self):
  52. return self.name
  53. class Meta:
  54. ordering = ('name',)
  55. class UserProfile(models.Model):
  56. user = models.OneToOneField(User, null=True)
  57. flavor = models.CharField(max_length=100)
  58. class Meta:
  59. ordering = ('flavor',)