Custom change_form.html

38 views
Skip to first unread message

Salvatore DI DIO

unread,
Sep 19, 2014, 10:43:00 AM9/19/14
to django...@googlegroups.com
Hello,

To follow my preceding question, on customize admin view, (
Helton Alves gave me a nice response).
I am wondering how to filter a list in change_form.html  admin  form, according to a partuculiar user ?

Thank you for your help

Regards




Collin Anderson

unread,
Sep 19, 2014, 7:33:42 PM9/19/14
to django...@googlegroups.com
if nothing else:

{% for item in list %}{% if item.user = user %}

{% endif %}{% endfor %}

Salvatore DI DIO

unread,
Sep 21, 2014, 7:33:20 AM9/21/14
to django...@googlegroups.com
Thank you Collin,

In fact I have not really access to the list.
II would like to flter a list wich is already rendered
as a listbox widget (fiedset.html)

Alex Chiaranda

unread,
Sep 21, 2014, 9:38:39 AM9/21/14
to django...@googlegroups.com
Hi Salvatore,

in your admin.py you can redefine your get_queryset and do something like this:


class FooAdmin(admin.ModelAdmin):
 
def get_queryset(self, request):
if not request.user.is_superuser:
return super(FooAdmin,self).get_queryset(request).filter(user=request.user) # here you can add any filter you want
return super(FooAdmin, self).get_queryset(request)



The if is not necessary, it is just to show you that you have the user object into the request. 

Salvatore DI DIO

unread,
Sep 21, 2014, 11:41:23 AM9/21/14
to django...@googlegroups.com
Thanks Alex,

This indeed allow me to filter the admin page which lists the albums.
But, the problem I have, is,  when I want to add an image.

The 'add' display a listbox containing all the albums the image can be attached to
And I want to filter the content of this listbox, showing only the albums created by the connected user

Regards
Reply all
Reply to author
Forward
0 new messages