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 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/033933b4-fb7b-46ca-bdf5-ada2011cb902%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to