Customise admin view
Hello, I am following a 'photo application' tutorial : http://lightbird.net/dbe/photo.html I have created several 'albums' to insert images in. I would like those albums beeing displayed in the admin panel according to each user or group Thank your for your help regards -- 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+unsubscr...@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/3ad874fd-9629-44e4-8cf4-0da6ac522492%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Customise admin view
Hy Elton, In fact each image belongs to an album. Let us say I have three album ALB1 ALB2 ALB3 In the admin form, when I add an image I can attach it to either of each Albums or all the three if I want What I would like is show the album list for a particuliar user. For example Tom could only add images in ALB1 Henry could add images in ALB2 and ALB3 I hope it's a little clearer Le jeudi 18 septembre 2014 14:05:13 UTC+2, Helton Alves a écrit : > > I didn't understand very well. > would you like the image of the tutorial? > > 2014-09-18 9:59 GMT+01:00 Salvatore DI DIO >: > >> Hello, >> >> I am following a 'photo application' tutorial : >> http://lightbird.net/dbe/photo.html >> I have created several 'albums' to insert images in. >> >> I would like those albums beeing displayed in the admin panel >> according to each user or group >> >> >> Thank your for your help >> >> regards >> >> >> >> -- >> 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...@googlegroups.com . >> To post to this group, send email to django...@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/3ad874fd-9629-44e4-8cf4-0da6ac522492%40googlegroups.com >> >> <https://groups.google.com/d/msgid/django-users/3ad874fd-9629-44e4-8cf4-0da6ac522492%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > > > > -- > > Helton Alves > Desenvolvedor web > Graduado em Sistemas de Informação - FACIMP > Cursando Metodologia do Ensino Superior - INESPO > -- 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+unsubscr...@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/e28b8164-017e-4932-8afc-f62533b6b02d%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Customise admin view
That's great Thank you very very much Helton Le jeudi 18 septembre 2014 15:44:44 UTC+2, Helton Alves a écrit : > > I think this will resolve your problem. :D > > in admin, you use the get_queryset. > in this case return only items of user, you can change this for return the > items that user have permission. > > class MyModelAdmin(admin.ModelAdmin): > def queryset(self, request): > qs = super(MyModelAdmin, self).queryset(request) > if request.user.is_superuser: > return qs > return qs.filter(author=request.user) > > > 2014-09-18 14:17 GMT+01:00 Salvatore DI DIO >: > >> Hy Elton, >> >> In fact each image belongs to an album. >> Let us say I have three album ALB1 ALB2 ALB3 >> >> In the admin form, when I add an image I can attach it to either of each >> Albums >> or all the three if I want >> >> What I would like is show the album list for a particuliar user. >> >> For example Tom could only add images in ALB1 >>Henry could add images in ALB2 and ALB3 >> >> >> I hope it's a little clearer >> >> >> >> >> >> >> >> Le jeudi 18 septembre 2014 14:05:13 UTC+2, Helton Alves a écrit : >>> >>> I didn't understand very well. >>> would you like the image of the tutorial? >>> >>> 2014-09-18 9:59 GMT+01:00 Salvatore DI DIO : >>> >>>> Hello, >>>> >>>> I am following a 'photo application' tutorial : >>>> http://lightbird.net/dbe/photo.html >>>> I have created several 'albums' to insert images in. >>>> >>>> I would like those albums beeing displayed in the admin panel >>>> according to each user or group >>>> >>>> >>>> Thank your for your help >>>> >>>> regards >>>> >>>> >>>> >>>> -- >>>> 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...@googlegroups.com. >>>> To post to this group, send email to django...@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/3ad874fd-9629-44e4-8cf4-0da6ac522492% >>>> 40googlegroups.com >>>> <https://groups.google.com/d/msgid/django-users/3ad874fd-9629-44e4-8cf4-0da6ac522492%40googlegroups.com?utm_medium=email&utm_source=footer> >>>> . >>>> For more options, visit https://groups.google.com/d/optout. >>>> >>> >>> >>> >>> -- >>> >>> Helton Alves >>> Desenvolvedor web >>> Graduado em Sistemas de Informação - FACIMP >>> Cursando Metodologia do Ensino Superior - INESPO >>> >> -- >> 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...@googlegroups.com . >> To post to this group, send email to django...@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/e28b8164-017e-4932-8afc-f62533b6b02d%40googlegroups.com >> >> <https://groups.google.com/d/msgid/django-users/e28b8164-017e-4932-8afc-f62533b6b02d%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> >> For more options, visit https://groups.google.com/d/optout. >> > > > > -- > > Helton Alves > Desenvolvedor web > Graduado em Sistemas de Informação - FACIMP > Cursando Metodologia do Ensino Superior - INESPO > -- 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+unsubscr...@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/6b84c3c8-9c0e-4f6e-8558-0793f55f11e5%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Custom change_form.html
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 -- 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+unsubscr...@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/3e916af0-17f8-4642-b226-aca71a08b289%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Custom change_form.html
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+unsubscr...@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/7dbcac7f-1c73-4b25-a0a1-a0329d36d6d7%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Accessing request object
Hello, Is it possible to access request object in 'helpers.py' file ? Ihave tried 'crequest' (from crequest.middleware import CrequestMiddleware) without luck. class AdminField(object): def __init__(self, form, field, is_first): self.field = form[field] # A django.forms.BoundField instance self.is_first = is_first # Whether this field is first on the line self.is_checkbox = isinstance(self.field.field.widget, forms.CheckboxInput) if (field == 'albums'): self.restrictQuery() def restrictQuery(self): from portfolio.models import Album #qs = Album.objects.filter(title='Famille') qs = Album.objects.all() self.field.field.queryset = qs I would like to access 'request.user' in 'restrictQuery Regards -- 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+unsubscr...@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/73622288-ada3-4555-920c-2d90e8624536%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
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+unsubscr...@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.
Solution : filtering listbox per user in 'admin add' form
This post follows my previous on filtering a listbox in 'admin add form' per user This is ceratinly a hack but It works for now, If you have a better solution, I would be glad to read it. In order to access the request object in '*/contrib/admin/helpers.py*' I modified the *'/contrib/admin/views/main.py*' def get_queryset(self, request): from django.conf import settings settings.CONNECTED_USER = str(request.user) And in '/contrib/admin/helpers.py' I can get the CONNECTED_USER and so could filter my list in the 'add' form from portfolio.models import Album from portfolio.models import User from django.conf import settings class AdminField(object): def __init__(self, form, field, is_first): self.field = form[field] # A django.forms.BoundField instance self.is_first = is_first # Whether this field is first on the line self.is_checkbox = isinstance(self.field.field.widget, forms.CheckboxInput) if (field == 'albums'): self.restrictAlbumQuery() def restrictAlbumQuery(self): # defined in main.py currentUser = settings.CONNECTED_USER qs = Album.objects.filter(user = User.objects.get(username=currentUser)) #here I can filter the albums listbx self.field.field.queryset = qs -- 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+unsubscr...@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/12321833-cdf7-4df7-bfa8-25502d3a27ce%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Testting field.label_tag
Hello, I woulk like to test field.label_tag in the fieldset.html template For example I want to do: {% if field.label_tag != 'Tags' %} {{ field.label_tag }} {% endif %} But that seems to not work Thanks for your suggestions -- 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+unsubscr...@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/f49e012b-34f7-4ca6-adf4-9663a9a626af%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Testting field.label_tag
Thank you Le lundi 22 septembre 2014 13:35:42 UTC+2, mb...@danir.us a écrit : > > Use the attribute ‘label’ rather than ‘label_tag’. The latter is the HTML > element. > > Do: > > {% if field.label != 'Tags' %} > {{ field.label_tag }} > {% endif %} > > Cheers > > > On Monday, September 22, 2014 10:51:59 AM UTC+2, Salvatore DI DIO wrote: >> >> Hello, >> >> I woulk like to test field.label_tag in the fieldset.html template >> >> For example I want to do: >> >> {% if field.label_tag != 'Tags' %} >> {{ field.label_tag }} >> {% endif %} >> >> But that seems to not work >> >> Thanks for your suggestions >> >> -- 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+unsubscr...@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/a85b8a99-4064-4919-b7cd-ac950e904a67%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Testting field.label_tag
Thank Daniel Le lundi 22 septembre 2014 14:05:33 UTC+2, Daniel Rus Morales a écrit : > > Use the attribute ‘label’ rather than ‘label_tal’. The latter is the HTML > element. > > Do: > > {% if field.label != 'Tags' %} > {{ field.label_tag }} > {% endif %} > > Cheers > > On 22 Sep 2014, at 10:51, Salvatore DI DIO > wrote: > > Hello, > > I woulk like to test field.label_tag in the fieldset.html template > > For example I want to do: > > {% if field.label_tag != 'Tags' %} > {{ field.label_tag }} > {% endif %} > > But that seems to not work > > Thanks for your suggestions > > > -- > 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...@googlegroups.com . > To post to this group, send email to django...@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/f49e012b-34f7-4ca6-adf4-9663a9a626af%40googlegroups.com > > <https://groups.google.com/d/msgid/django-users/f49e012b-34f7-4ca6-adf4-9663a9a626af%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > > > -- 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+unsubscr...@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/bbd49f0d-2a3b-4b28-a8e5-5d34d6023f2f%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Accessing request object
Excuse me Collin, I don't understang what you are meaning ... Le lundi 22 septembre 2014 17:46:41 UTC+2, Collin Anderson a écrit : > > Can you attach the request to `form.request`? > -- 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+unsubscr...@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/b024d07f-b718-4d7b-93ac-9a382b8cec36%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Accessing request object
I understand now, Thank you very much Altus and Collin 2014-09-23 1:30 GMT+02:00 alTus : > Collin said you can attach your `request` object to the form object > somewhere in your view. After that you will be able to use in anywhere in > methods. > Also you can consider adding request parameter explicitly to your > __init__ method and then passing it to `restrictQuery`. > > PS. restrictQuery should be named restrict_query according to python > style guide. > > воскресенье, 21 сентября 2014 г., 15:38:23 UTC+4 пользователь Salvatore DI > DIO написал: > >> Hello, >> >> Is it possible to access request object in 'helpers.py' file ? >> Ihave tried 'crequest' (from crequest.middleware import >> CrequestMiddleware) >> without luck. >> >> >> class AdminField(object): >> def __init__(self, form, field, is_first): >> self.field = form[field] # A django.forms.BoundField instance >> self.is_first = is_first # Whether this field is first on the >> line >> self.is_checkbox = isinstance(self.field.field.widget, >> forms.CheckboxInput) >> if (field == 'albums'): >> self.restrictQuery() >> >> def restrictQuery(self): >> from portfolio.models import Album >> #qs = Album.objects.filter(title='Famille') >> qs = Album.objects.all() >> self.field.field.queryset = qs >> >> >> I would like to access 'request.user' in 'restrictQuery >> >> Regards >> >> >> -- > You received this message because you are subscribed to a topic in the > Google Groups "Django users" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/django-users/B4m9ki4hqp8/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > django-users+unsubscr...@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/033933b4-fb7b-46ca-bdf5-ada2011cb902%40googlegroups.com > <https://groups.google.com/d/msgid/django-users/033933b4-fb7b-46ca-bdf5-ada2011cb902%40googlegroups.com?utm_medium=email&utm_source=footer> > . > > For more options, visit https://groups.google.com/d/optout. > -- 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+unsubscr...@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/CAPj0iHuNFTQeqtu8dr56XLpviBwC1rmuWZxWe9FOm69aw206mA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.