Seems good to me. You could have a preferences model which has a one-
to-one relationship to a User. Your method is sound that it saves an
additional SQL query to get the extra info, but if you have the auth
context processor enabled you can always do:

{{ user.preferences.employee }} # where employee is the field for
employee.

If you are going to allow only a small number of choices you could use
an IntegerField with the choices keyword. Then you'd have to do:

{{ user.preferences.get_employee_display }}

While this method results in an extra SQL query per view that displays
the info, it's not going to break the bank in terms of performance.
This way if you allow the user to change their preferences you don't
have to worry about stale settings in the cache.

Alternatively you could write your own context that selected the User
object from the DB and did a select related for preferences to make
sure Django executes an INNER JOIN.

Best of luck, Euan



On 2 July, 23:52, zweb <[email protected]> wrote:
> On my web pages I have  labels for text fields. I want user to be able
> to personalize the labels.
>
> Example :
> default label: Employee, alternative is that user can choose and
> save-  Associate or Staff Member as label to be shown on all screens.
>
> Approach I can think of:
>
> 1. When user logs in - gets his preferences from DB and save it in
> session.
>
> 2. I create a custom template tag {% getlabeltext Employee %}
>
> which is something like ( following is the psuedo code)
>
> def getlabeltext(label):
> ''' if user has choosen another label use it else return the
> default.'''
>    if label in request.session:
>         return request.session[label]
>    else:
>        return label
>
> Is there a better approach I should look at?

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