I understand now,

Thank you very much Altus and Collin


2014-09-23 1:30 GMT+02:00 alTus <mortas...@gmail.com>:

> 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.

Reply via email to