Django在管理员中从1.2.5升级到1.3错误

时间:2016-06-03 17:22:14

标签: python django django-admin upgrade django-1.3

我正在尝试将运行django 1.2.5的网站升级到1.3 到目前为止我遇到的唯一错误是在网站的管理部分:

__init__() got an unexpected keyword argument 'field_path'

我认为这是来自此代码中的某个地方:

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",
        ]

我该如何解决这个问题?

下面的完整堆栈跟踪:

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'

2 个答案:

答案 0 :(得分:1)

实际上是导致问题的start_date字段,我将其跟踪到models.py文件中的过滤器类,并在此帖子中提供了一些帮助:

django admin custom list_filter

感谢指点!

答案 1 :(得分:0)

很难确切地说出这里有什么问题。

在名为filterspecs.py的文件中触发错误。我怀疑这可能是因为您有一个未包含在is_series中的列表过滤器self.list_display

尝试注释掉list_filter行,看看是否会发生任何变化。

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

它也可能是在更高版本的django中修复的一些错误。由于admin.py文件是可选的,您可以在升级过程中删除或重命名它们,直到您修复了其他问题。此错误可能是由更高版本的django中修复的问题引起的。