On Sat, 2008-01-05 at 04:12 -0800, pinco wrote:
> Hi,
> 
> I'm trying to figure out how to solve the following issue without
> succeed.
> 
> I have a model like this:
> 
> class Product(models.Model):
>    ...
>    measure_cm = models.FloatField(...)
>    measure_in = models.FloatField(...)
>   ...
> 
> The fields contain the same information (a relevant dimension of a
> product) expressed in centimeter and in inches respectively.
> 
> I would able, in the view and in the template, to do something like
> this:
> 
> ...
> this_product = Product.objects.get(pk=product_id)
> this_product_measure = this_product.measure
> 
> and dynamically assigning to this_product_measure the value of
> this_product.measure_cm or this_product.measure_in based on a variable
> stored in the session, representing a user preference.

For a template, you could write a context processor that puts the
computed value into the template's context each time.

For a view, you could write a method on the model that accepts the
"user" object and returns the correct value. It doesn't even have to be
a method on the model -- it could just be a separate helper function.
The point is that you're going to have to pass in the user object each
time anyway, since there's no way to magically read that out of thin
air.

Regards,
Malcolm

-- 
No one is listening until you make a mistake. 
http://www.pointy-stick.com/blog/


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to