mirror of
https://github.com/django/django.git
synced 2025-10-27 07:36:08 +00:00
Fixed #12245 -- Corrected target app handling for auto-generated m2m models when the parent model isn't in the models module (or a subpackage thereof). Thanks to emulbreh for the report and patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@11755 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -835,20 +835,13 @@ def create_many_to_many_intermediary_model(field, klass):
|
||||
'db_table': field._get_m2m_db_table(klass._meta),
|
||||
'managed': managed,
|
||||
'auto_created': klass,
|
||||
'app_label': klass._meta.app_label,
|
||||
'unique_together': (from_, to)
|
||||
})
|
||||
# If the models have been split into subpackages, klass.__module__
|
||||
# will be the subpackge, not the models module for the app. (See #12168)
|
||||
# Compose the actual models module name by stripping the trailing parts
|
||||
# of the namespace until we find .models
|
||||
parts = klass.__module__.split('.')
|
||||
while parts[-1] != 'models':
|
||||
parts.pop()
|
||||
module = '.'.join(parts)
|
||||
# Construct and return the new class.
|
||||
return type(name, (models.Model,), {
|
||||
'Meta': meta,
|
||||
'__module__': module,
|
||||
'__module__': klass.__module__,
|
||||
from_: models.ForeignKey(klass, related_name='%s+' % name),
|
||||
to: models.ForeignKey(to_model, related_name='%s+' % name)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user