views:

848

answers:

3

I'm trying to make a custom view in Django admin. I'm reading from this site, Simple Django Admin Preview, but I have a problem:

ValueError: invalid literal for int() with base 10: '13/preview'

Here is my url.py:

url(r'^admin/diligencias/diligencia/(?P<object_id>\d+)/preview/$','preview'),

Here is my view.py:

@staff_member_required
def preview(request, object_id):
   return object_detail(request, object_id=object_id,queryset=Diligencia.objects.all(), template_object_name = 'diligencia', )

What does this error mean?

+1  A: 

What Gabriel says is incorrect. My guess is the problem is that your view is after the other admin views in the URLConf, therefore this URL gets caught by a catchall one the Django amdin uses the "13/preview" could be a valid PK, therefore you should move this URL above the other admin ones.

Alex Gaynor
+4  A: 

The request isn't being picked up by that URLconf, but by the default admin view, which expects everything after the app/model to be the integer value of the primary key.

You may need to move your URL higher in the list of URLs, so that it comes before the one that includes the admin urls.

Daniel Roseman
Thanks Daniel, now i have a new one error:Traceback (most recent call last): File "/home/iosira05/webapps/django/lib/python2.5/django/core/handlers/base.py", line 92, in get_response response = callback(request, *callback_args, **callback_kwargs)TypeError: 'str' object is not callable
Asinox
A: 

i think you should pass an int object to object_detail function for object_id test this:


@staff_member_required
def preview(request, object_id):
   object_id = int(object_id)
   return object_detail(request, object_id=object_id,queryset=Diligencia.objects.all(), template_object_name = 'diligencia', )

Mehran