简体   繁体   中英

Django upgrade from 1.2.5 to 1.3 error in admin

I am attempting to upgrade a website running django 1.2.5 to 1.3 The only error I have encountered so far is in the admin part of the site:

__init__() got an unexpected keyword argument 'field_path'

which I think is from somewhere in this code:

class EventAdmin(admin.ModelAdmin):
    inlines = [EventArtistsInline, EventGalleryInline, EventRelatedObjectInline, EventPriceInline, SeriesPassInline, EventsInSeriesInline, ]
    save_as = True
    prepopulated_fields = {"slug": ("prefix", "title", "suffix")}
    list_filter = ('start_date', 'is_series')
    search_fields = ['title', 'description', 'intro',]

    def changelist_view(self, request, extra_context=None):
        if request.user.is_superuser:
            self.list_display_links = ['title']
            self.list_display= ['title', 'status', 'start_date', 'end_date', 'hide_artists', 'featured', 'is_series', 'tickets_sold', 'tickets_remaining', 'sold_out']
            self.list_editable = ['featured', 'status', 'hide_artists', 'is_series','sold_out',]
        else:
            self.list_display_links = ['']
            self.list_display= ['title', 'status', 'start_date', 'tickets_sold', 'tickets_remaining', 'sold_out']
            self.list_editable = ['status']
        return super(EventAdmin, self).changelist_view(request, extra_context)

    class Media:
        js = [
            settings.MEDIA_URL+'tiny_mce/tiny_mce.js',
            settings.MEDIA_URL+"filebrowser/js/TinyMCEAdmin.js",
        ]

How can I fix this?

Full stack trace below:

Environment:


Request Method: POST
Request URL: http://example.com/admin/events/event/

Django Version: 1.3
Python Version: 2.7.6
Installed Applications:
['grappelli',
 'admin_tools',
 'admin_tools.theming',
 'admin_tools.menu',
 'admin_tools.dashboard',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.sitemaps',
 'filebrowser',
 'galleries',
 'products',
 'django.contrib.admin',
 'django.contrib.redirects',
 'django.contrib.humanize',
 'kp.applications.seasonal_dates',
 'kp.utils',
 'people',
 'pages',
 'archive',
 'locations',
 'partners',
 'campaigns',
 'events',
 'memberships',
 'registration',
 'captcha',
 'session_cart',
 'colours',
 'order',
 'genres',
 'mamona',
 'musicshop',
 'mamona.backends.stripe',
 'django.contrib.humanize',
 'django.contrib.auth',
 'email_usernames',
 'profiles',
 'landing_pages',
 'easy_thumbnails',
 'emailmgr',
 'filebrowser']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.contrib.redirects.middleware.RedirectFallbackMiddleware',
 'session_cart.middleware.CartMiddleware')


Traceback:
File "/var/projects/example.com/env/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "/var/projects/example.com/env/local/lib/python2.7/site-packages/django/contrib/admin/options.py" in wrapper
  307.                 return self.admin_site.admin_view(view)(*args, **kwargs)
File "/var/projects/example.com/env/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
  93.                     response = view_func(request, *args, **kwargs)
File "/var/projects/example.com/env/local/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  79.         response = view_func(request, *args, **kwargs)
File "/var/projects/example.com/env/local/lib/python2.7/site-packages/django/contrib/admin/sites.py" in inner
  197.             return view(request, *args, **kwargs)
File "./events/admin.py" in changelist_view
  55.         return super(EventAdmin, self).changelist_view(request, extra_context)
File "/var/projects/example.com/env/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapper
  28.             return bound_func(*args, **kwargs)
File "/var/projects/example.com/env/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
  93.                     response = view_func(request, *args, **kwargs)
File "/var/projects/example.com/env/local/lib/python2.7/site-packages/django/utils/decorators.py" in bound_func
  24.                 return func(self, *args2, **kwargs2)
File "/var/projects/example.com/env/local/lib/python2.7/site-packages/django/contrib/admin/options.py" in changelist_view
  1056.                 self.list_select_related, self.list_per_page, self.list_editable, self)
File "/var/projects/example.com/env/local/lib/python2.7/site-packages/django/contrib/admin/views/main.py" in __init__
  67.         self.filter_specs, self.has_filters = self.get_filters(request)
File "/var/projects/example.com/env/local/lib/python2.7/site-packages/django/contrib/admin/views/main.py" in get_filters
  77.                                          field_path=filter_name)
File "/var/projects/example.com/env/local/lib/python2.7/site-packages/django/contrib/admin/filterspecs.py" in create
  39.                                field_path=field_path)

Exception Type: TypeError at /admin/events/event/
Exception Value: __init__() got an unexpected keyword argument 'field_path'

It was actually the start_date field that was causing the problem and I tracked this down to a filter class in the models.py file, with a bit of help from this post:

django admin custom list_filter

thanks for the pointers!

It's hard to tell exactly what is wrong here.

The error is triggered in a file called filterspecs.py . I suspect that it might be because you have a list filter is_series that is not included in the self.list_display .

Try to comment out the list_filter line, and see if that changes anything.

list_filter = ('start_date', 'is_series')
self.list_display= ['title', 'status', 'start_date', 'tickets_sold', 
                    'tickets_remaining', 'sold_out']

It could also be some bug that was fixed in a later version of django. Since having admin.py files are optional, you could just delete or rename them during the upgrade process until you have fixed other problems. This error might be caused by a problem that was fixed in a later version of django.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM