2013-02-25 00:09:13 +01:00
|
|
|
from __future__ import unicode_literals
|
2013-01-29 06:28:09 +01:00
|
|
|
|
2013-02-25 00:09:13 +01:00
|
|
|
from django.db import models
|
|
|
|
from django.utils import six
|
2013-01-29 06:28:09 +01:00
|
|
|
|
2013-02-25 00:09:13 +01:00
|
|
|
|
|
|
|
# The models definitions below used to crash. Generating models dynamically
|
2013-12-24 12:25:17 +01:00
|
|
|
# at runtime is a bad idea because it pollutes the app registry. This doesn't
|
2013-02-25 00:09:13 +01:00
|
|
|
# integrate well with the test suite but at least it prevents regressions.
|
|
|
|
|
|
|
|
|
|
|
|
class CustomBaseModel(models.base.ModelBase):
|
2013-01-29 06:28:09 +01:00
|
|
|
pass
|
2013-02-25 00:09:13 +01:00
|
|
|
|
|
|
|
|
|
|
|
class MyModel(six.with_metaclass(CustomBaseModel, models.Model)):
|
2013-05-19 10:36:04 +02:00
|
|
|
"""Model subclass with a custom base using six.with_metaclass."""
|
2013-02-25 00:09:13 +01:00
|
|
|
|
2013-05-19 10:36:04 +02:00
|
|
|
# This is done to ensure that for Python2 only, defining metaclasses
|
|
|
|
# still does not fail to create the model.
|
2013-02-25 00:09:13 +01:00
|
|
|
|
2013-09-02 12:06:32 +02:00
|
|
|
if six.PY2:
|
2013-10-10 17:07:48 +02:00
|
|
|
class MyPython2Model(models.Model):
|
2013-02-25 00:09:13 +01:00
|
|
|
"""Model subclass with a custom base using __metaclass__."""
|
|
|
|
__metaclass__ = CustomBaseModel
|