1
0
mirror of https://github.com/django/django.git synced 2024-11-20 08:24:58 +00:00
django/tests/base/models.py
Andrea Crotti 5124ab7620 add comment to explain why it's necessary to do an explicit check for
Python2 and how metaclasses are defined
2013-05-19 10:36:04 +02:00

26 lines
794 B
Python

from __future__ import unicode_literals
from django.db import models
from django.utils import six
# The models definitions below used to crash. Generating models dynamically
# at runtime is a bad idea because it pollutes the app cache. This doesn't
# integrate well with the test suite but at least it prevents regressions.
class CustomBaseModel(models.base.ModelBase):
pass
class MyModel(six.with_metaclass(CustomBaseModel, models.Model)):
"""Model subclass with a custom base using six.with_metaclass."""
# This is done to ensure that for Python2 only, defining metaclasses
# still does not fail to create the model.
if not six.PY3:
class MyModel(models.Model):
"""Model subclass with a custom base using __metaclass__."""
__metaclass__ = CustomBaseModel