Is it bad form in Django to add "transient" instance variables to
model instances?
I'm rendering a set of search results. Each result record is a User
instance. I want to show whether or not each record is a friend of
the user who is conducting the search.
Right now my view is annotating each search result record to indicate
whether or not it is a friend of the requesting user. This works, but
I'm not sure what might break as a result of adding the instance
variable:
matched_users = User.objects.filter(...)
friends_set = set([...])
for u in matched_users:
u.is_my_friend = (u.username in friends_set)
I don't need to store this information permanently. I just want to
use it to simplify template rendering, e.g.
{% for user in matched_users %}
...
{% if user.is_my_friend %}
{{user.username}} is already your friend.
{% endif %}
...
Is there a different, recommended way to do this? Thanks for the help!
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---