Custom change_form.html

38 visualizzazioni
Passa al primo messaggio da leggere

Salvatore DI DIO

da leggere,
19 set 2014, 10:43:0019/09/14
a 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

da leggere,
19 set 2014, 19:33:4219/09/14
a django...@googlegroups.com
if nothing else:

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

{% endif %}{% endfor %}

Salvatore DI DIO

da leggere,
21 set 2014, 07:33:2021/09/14
a 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

da leggere,
21 set 2014, 09:38:3921/09/14
a 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

da leggere,
21 set 2014, 11:41:2321/09/14
a 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
Rispondi a tutti
Rispondi all'autore
Inoltra
0 nuovi messaggi