Sunday, September 21, 2014

Re: Custom change_form.html

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


Le dimanche 21 septembre 2014 15:38:39 UTC+2, Alex Chiaranda a écrit :
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. 



On Sunday, September 21, 2014 8:33:20 AM UTC-3, Salvatore DI DIO wrote:
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)



Le samedi 20 septembre 2014 01:33:42 UTC+2, Collin Anderson a écrit :
if nothing else:

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

{% endif %}{% endfor %}

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/96f7f978-8390-4b28-97ca-8b30dc874d05%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment