On Mon, Feb 11, 2013 at 10:05 AM, frocco <[email protected]> wrote:

> What I am trying to do, is I have four price fields in my model and need
> to return just one based on current user logged in.
>
> price_a
> price_b
> price_c
> price_d
>
> I want to always return a field named price, based on one of those fields.
>
>
> On Monday, February 11, 2013 9:51:47 AM UTC-5, frocco wrote:
>>
>> Ok, but is request available in models.py?
>>
>>
>> On Monday, February 11, 2013 9:49:47 AM UTC-5, sandy wrote:
>>>
>>> On Mon, Feb 11, 2013 at 7:42 PM, frocco <[email protected]> wrote:
>>> > Hello,
>>> >
>>> > I have some logic I want to put in a model, but it requires know the
>>> current
>>> > user logged in.
>>> > Is there a way to get this?
>>> >
>>> This gets the current logged in user :
>>>
>>> current_user = request.user
>>>
>>> --
>>> Sandeep Kaur
>>> E-Mail: [email protected]
>>> Blog: sandymadaan.wordpress.com
>>>
>>
>
> There is only such a thing as a current user during a request.  The view
knows the request.  The request can be known in template context if the
view allows it (e.g.; uses a request context).  Any model method that
depends on information from the request (like request.user) needs to be
passed that information as an argument).  While you can't pass an argument
to a method being called using vanilla template syntax, you could write a
custom template tag, allowing, for example {% get_user_specific_price
model_instance %} .  (Tags have access to the context, so you need not pass
it explicitly.  Your view would still need to add request or request.user
to the context, unless you use a suitable template context processor to do
so.)

Bill

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to