Thanks Brad, I got it working.
@register.filter(name='price') def price(model, user): u = UserGroup.objects.get(user_id=user.id) level = u.price_level if level == 'B': return model.price_b if level == 'C': return model.price_c if level == 'D': return model.price_d if level == 'E': return model.price_e return model.price_a {{ row|price:request.user }} On Monday, February 11, 2013 10:54:53 AM UTC-5, Brad Pitcher wrote: > > Sounds like you are maybe calling a user method from a template? You > will probably want to create a custom tag or filter: > https://docs.djangoproject.com/en/1.4/howto/custom-template-tags/ > > A filter would look like this: > {{ my_model_item|price:request.user }} > > And the filter itself something like this: > > def price(my_model_item, user): > """Returns the price for the user""" > # Logic to evaluate the price could be here on in a > # model method, but if it's in the model method you > # will need to pass the user as a parameter to that > # method. > return evaluated_price > > On Mon, 2013-02-11 at 07:05 -0800, frocco 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 > > <far...@gmail.com> 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: mkaur...@gmail.com > > Blog: sandymadaan.wordpress.com > > > > -- > > 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 <javascript:>. > > To post to this group, send email to > > django...@googlegroups.com<javascript:>. > > > Visit this group at http://groups.google.com/group/django-users?hl=en. > > For more options, visit https://groups.google.com/groups/opt_out. > > > > > > > -- 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.