Last active
August 29, 2015 14:05
-
-
Save squiddy/2913590c6867e302b548 to your computer and use it in GitHub Desktop.
Django 1.5.9 - DisallowedModelAdminToField for M2N Through Object
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib import admin | |
from barbaz.models import A, Through | |
class ThroughInline(admin.TabularInline): | |
model = Through | |
fk_name = 'a1' | |
raw_id_fields = ['a2'] | |
class AAdmin(admin.ModelAdmin): | |
inlines = [ThroughInline] | |
admin.site.register(A, AAdmin) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The exception happens when clicking on the raw_id_fields magnifying glass in the admin, the popup will show the exception. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
class A(models.Model): | |
bs = models.ManyToManyField('self', symmetrical=False, through='Through') | |
class Through(models.Model): | |
a1 = models.ForeignKey(A, related_name='a1_set') | |
a2 = models.ForeignKey(A, related_name='a2_set') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Traceback: | |
File "/tmp/env/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response | |
113. response = callback(request, *callback_args, **callback_kwargs) | |
File "/tmp/env/lib/python2.7/site-packages/django/contrib/admin/options.py" in wrapper | |
390. return self.admin_site.admin_view(view)(*args, **kwargs) | |
File "/tmp/env/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view | |
91. response = view_func(request, *args, **kwargs) | |
File "/tmp/env/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func | |
89. response = view_func(request, *args, **kwargs) | |
File "/tmp/env/lib/python2.7/site-packages/django/contrib/admin/sites.py" in inner | |
202. return view(request, *args, **kwargs) | |
File "/tmp/env/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapper | |
25. return bound_func(*args, **kwargs) | |
File "/tmp/env/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view | |
91. response = view_func(request, *args, **kwargs) | |
File "/tmp/env/lib/python2.7/site-packages/django/utils/decorators.py" in bound_func | |
21. return func(self, *args2, **kwargs2) | |
File "/tmp/env/lib/python2.7/site-packages/django/contrib/admin/options.py" in changelist_view | |
1198. self) | |
File "/tmp/env/lib/python2.7/site-packages/django/contrib/admin/views/main.py" in __init__ | |
64. raise DisallowedModelAdminToField("The field %s cannot be referenced." % to_field) | |
Exception Type: DisallowedModelAdminToField at /admin/barbaz/a/ | |
Exception Value: The field id cannot be referenced. |
Never mind; you guys fixed it in 1.5.12, so we just upgraded to that instead. SCIENCE.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey Squiddy:
I work for Sosh and we're still on Django 1.5.9. I'm getting this bug right now and was wondering if you found a workaround for it, or if we're just SOL until we upgrade Django.
Thanks,
Alek Sharma