models.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # -*- coding: utf-8 -*-
  2. from __future__ import unicode_literals
  3. from django.apps.registry import Apps
  4. from django.db import models
  5. from django.utils import six
  6. from django.utils.encoding import python_2_unicode_compatible
  7. class CustomModelBase(models.base.ModelBase):
  8. pass
  9. class ModelWithCustomBase(six.with_metaclass(CustomModelBase, models.Model)):
  10. pass
  11. @python_2_unicode_compatible
  12. class UnicodeModel(models.Model):
  13. title = models.CharField('ÚÑÍ¢ÓÐÉ', max_length=20, default='“Ðjáñgó”')
  14. class Meta:
  15. # Disable auto loading of this model as we load it on our own
  16. apps = Apps()
  17. verbose_name = 'úñí©óðé µóðéø'
  18. verbose_name_plural = 'úñí©óðé µóðéøß'
  19. def __str__(self):
  20. return self.title
  21. class Unserializable(object):
  22. """
  23. An object that migration doesn't know how to serialize.
  24. """
  25. pass
  26. class UnserializableModel(models.Model):
  27. title = models.CharField(max_length=20, default=Unserializable())
  28. class Meta:
  29. # Disable auto loading of this model as we load it on our own
  30. apps = Apps()
  31. class UnmigratedModel(models.Model):
  32. """
  33. A model that is in a migration-less app (which this app is
  34. if its migrations directory has not been repointed)
  35. """
  36. pass
  37. class EmptyManager(models.Manager):
  38. use_in_migrations = True
  39. class FoodQuerySet(models.query.QuerySet):
  40. pass
  41. class BaseFoodManager(models.Manager):
  42. def __init__(self, a, b, c=1, d=2):
  43. super(BaseFoodManager, self).__init__()
  44. self.args = (a, b, c, d)
  45. class FoodManager(BaseFoodManager.from_queryset(FoodQuerySet)):
  46. use_in_migrations = True
  47. class NoMigrationFoodManager(BaseFoodManager.from_queryset(FoodQuerySet)):
  48. pass