Opened 10 years ago

Last modified 10 years ago

#23616 closed Bug

'GenericRel' object has no attribute 'get_related_field' — at Initial Version

Reported by: ranjur Owned by: nobody
Component: contrib.contenttypes Version: 1.7
Severity: Release blocker Keywords: GenericRel, django 1.7, admin, get_related_field, GenericRelation
Cc: ranju.five@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I have a model:
#models.py
class TaggedItem(models.Model):

tag = models.SlugField()
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = GenericForeignKey('content_type', 'object_id')

def str(self): # unicode on Python 2

return self.tag

And model with GenericRelation
class Bookmark(models.Model):

url = models.URLField()
tags = GenericRelation(TaggedItem)

#admin.py
class BookmarkAdmin(admin.ModelAdmin):

list_filter = ('tagstag')

admin.site.register(models.Bookmark, BookmarkAdmin)

It will list all the tag in the filter, but when I try to filter it throws error 'GenericRel' object has no attribute 'get_related_field'

Full stack:

AttributeError at /admin/app/bookmark
'GenericRel' object has no attribute 'get_related_field'
Request Method:	GET
Request URL:	http://127.0.0.1:8000/admin/app/bookmark/?q=&tags__tag__id__exact=1
Django Version:	1.7
Exception Type:	AttributeError
Exception Value:	
'GenericRel' object has no attribute 'get_related_field'
Exception Location:	/home/user/virtual/test/local/lib/python2.7/site-packages/django/contrib/admin/options.py in lookup_allowed, line 416
Python Executable:	/home/user/virtual/test/bin/python
Python Version:	2.7.6
Python Path:	
['/home/user/projects/ptest',
 '/home/user/virtual/test/local/lib/python2.7/site-packages/Pillow-2.5.1-py2.7-linux-x86_64.egg',
 '/home/user/virtual/test/src/cmsplugin-bootstrap-carousel',
 '/home/user/virtual/test/src/cmsplugin-contact',
 '/home/user/virtual/test/src/django-faq',
 '/home/user/virtual/test/src/python-varnish',
 '/home/user/virtual/test/src/cmsplugin-text-ng',
 '/home/user/virtual/test/src/django-balancer',
 '/home/user/virtual/test/src/django-nose',
 '/home/user/virtual/test/lib/python2.7',
 '/home/user/virtual/test/lib/python2.7/plat-x86_64-linux-gnu',
 '/home/user/virtual/test/lib/python2.7/lib-tk',
 '/home/user/virtual/test/lib/python2.7/lib-old',
 '/home/user/virtual/test/lib/python2.7/lib-dynload',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-x86_64-linux-gnu',
 '/usr/lib/python2.7/lib-tk',
 '/home/user/virtual/test/local/lib/python2.7/site-packages',
 '/home/user/virtual/test/local/lib/python2.7/site-packages/PIL',
 '/home/user/virtual/test/local/lib/python2.7/site-packages/newrelic-2.28.0.26',
 '/home/user/projects/y1/test']
Server time:	Wed, 8 Oct 2014 13:28:38 +0800
Traceback Switch to copy-and-paste view

/home/user/virtual/test/local/lib/python2.7/site-packages/django/core/handlers/base.py in get_response
                    response = wrapped_callback(request, *callback_args, **callback_kwargs) ...
▶ Local vars
/home/user/virtual/test/local/lib/python2.7/site-packages/django/contrib/admin/options.py in wrapper
                return self.admin_site.admin_view(view)(*args, **kwargs) ...
▶ Local vars
/home/user/virtual/test/local/lib/python2.7/site-packages/django/utils/decorators.py in _wrapped_view
                    response = view_func(request, *args, **kwargs) ...
▶ Local vars
/home/user/virtual/test/local/lib/python2.7/site-packages/django/views/decorators/cache.py in _wrapped_view_func
        response = view_func(request, *args, **kwargs) ...
▶ Local vars
/home/user/virtual/test/local/lib/python2.7/site-packages/django/contrib/admin/sites.py in inner
            return view(request, *args, **kwargs) ...
▶ Local vars
/home/user/virtual/test/local/lib/python2.7/site-packages/django/utils/decorators.py in _wrapper
            return bound_func(*args, **kwargs) ...
▶ Local vars
/home/user/virtual/test/local/lib/python2.7/site-packages/django/utils/decorators.py in _wrapped_view
                    response = view_func(request, *args, **kwargs) ...
▶ Local vars
/home/user/virtual/test/local/lib/python2.7/site-packages/django/utils/decorators.py in bound_func
                return func.__get__(self, type(self))(*args2, **kwargs2) ...
▶ Local vars
/home/user/virtual/test/local/lib/python2.7/site-packages/django/contrib/admin/options.py in changelist_view
                self.list_max_show_all, self.list_editable, self) ...
▶ Local vars
/home/user/virtual/test/local/lib/python2.7/site-packages/django/contrib/admin/views/main.py in __init__
        self.queryset = self.get_queryset(request) ...
▶ Local vars
/home/user/virtual/test/local/lib/python2.7/site-packages/django/contrib/admin/views/main.py in get_queryset
         filters_use_distinct) = self.get_filters(request) ...
▶ Local vars
/home/user/virtual/test/local/lib/python2.7/site-packages/django/contrib/admin/views/main.py in get_filters
            if not self.model_admin.lookup_allowed(key, value): ...
▶ Local vars
/home/user/virtual/test/local/lib/python2.7/site-packages/django/contrib/admin/options.py in lookup_allowed
                rel_name = field.rel.get_related_field().name ...
▶ Local vars

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top