I have a Settings model that contains settings for my application. class Settings(models.Model): database_name = models.CharField(max_length=50) current_campaign = models.ForeignKey('Campaign')
It only contains one object. I would like to be able to use the admin pages to edit it. Since it only contains one object, I would like to skip the changelist_view page and go directly to the change_view page. I figured I could get the object_id of the single object and simply override changelist_view by replacing it with a call to change_view. Here is my admin.py I thought would work: from wolkdata.database.models import * from django.contrib import admin class SettingsAdmin(admin.ModelAdmin): def changelist_view(self, request, extra_context=None): object_id = Settings.objects.all()[0].id return super(SettingsAdmin, self).change_view(self, request, object_id, extra_context=None) admin.site.register(Settings, SettingsAdmin) Unfortunately, it gave the following error: Traceback: File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/ base.py" in get_response 100. response = callback(request, *callback_args, **callback_kwargs) File "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/ options.py" in wrapper 239. return self.admin_site.admin_view(view)(*args, **kwargs) File "/usr/local/lib/python2.6/dist-packages/django/utils/ decorators.py" in _wrapped_view 76. response = view_func(request, *args, **kwargs) File "/usr/local/lib/python2.6/dist-packages/django/views/decorators/ cache.py" in _wrapped_view_func 69. response = view_func(request, *args, **kwargs) File "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/ sites.py" in inner 190. return view(request, *args, **kwargs) File "/home/bruce/django/wolkdata/../wolkdata/database/admin.py" in changelist_view 7. return super(SettingsAdmin, self).change_view(self, request, object_id, extra_context=None) File "/usr/local/lib/python2.6/dist-packages/django/utils/ decorators.py" in _wrapper 21. return decorator(bound_func)(*args, **kwargs) File "/usr/local/lib/python2.6/dist-packages/django/utils/ decorators.py" in _wrapped_view 72. result = middleware.process_view(request, view_func, args, kwargs) File "/usr/local/lib/python2.6/dist-packages/django/middleware/ csrf.py" in process_view 83. request.META["CSRF_COOKIE"] = request.COOKIES[settings.CSRF_COOKIE_NAME] Exception Type: AttributeError at /admin/database/settings/ Exception Value: 'SettingsAdmin' object has no attribute 'COOKIES' Can anyone see what I am doing wrong? Could it possibly have something to do with the decorators? Thanks. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.