mirror of
https://github.com/Hopiu/django-modeltranslation.git
synced 2026-04-20 21:20:59 +00:00
Small cleanup in `FieldsAggregationMetaClass`. The manual inheritance syntax is left mostly for backwards compatibility.
This commit is contained in:
parent
36c5d0b81a
commit
11045e8ffb
1 changed files with 7 additions and 9 deletions
|
|
@ -5,7 +5,7 @@ from django.db.models.base import ModelBase
|
|||
|
||||
from modeltranslation.fields import TranslationFieldDescriptor, create_translation_field
|
||||
from modeltranslation.manager import MultilingualManager, rewrite_lookup_key
|
||||
from modeltranslation.utils import build_localized_fieldname, unique
|
||||
from modeltranslation.utils import build_localized_fieldname
|
||||
|
||||
|
||||
class AlreadyRegistered(Exception):
|
||||
|
|
@ -22,16 +22,14 @@ class DescendantRegistered(Exception):
|
|||
|
||||
class FieldsAggregationMetaClass(type):
|
||||
"""
|
||||
Metaclass to handle inheritance of fields between classes.
|
||||
Metaclass to handle custom inheritance of fields between classes.
|
||||
"""
|
||||
def __new__(cls, name, bases, attrs):
|
||||
parents = [b for b in bases if isinstance(b, FieldsAggregationMetaClass)]
|
||||
if not parents:
|
||||
return super(FieldsAggregationMetaClass, cls).__new__(cls, name, bases, attrs)
|
||||
attrs['fields'] = tuple(attrs.get('fields', ()))
|
||||
for base in parents:
|
||||
attrs['fields'] += tuple(base.fields)
|
||||
attrs['fields'] = tuple(unique(attrs['fields']))
|
||||
attrs['fields'] = set(attrs.get('fields', ()))
|
||||
for base in bases:
|
||||
if isinstance(base, FieldsAggregationMetaClass):
|
||||
attrs['fields'].update(base.fields)
|
||||
attrs['fields'] = tuple(attrs['fields'])
|
||||
return super(FieldsAggregationMetaClass, cls).__new__(cls, name, bases, attrs)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue