Note that there are some explanatory texts on larger screens.

plurals
  1. POget request.session from a model method in django
    primarykey
    data
    text
    <p>Hay, is it possible to a get a request.session value from a model method in django?</p> <p><strong>MEGA UPDATE</strong></p> <p>Here is my model</p> <pre><code>class GameDiscussion(models.Model): game = models.ForeignKey(Game) message = models.TextField() reply_to = models.ForeignKey('self', related_name='replies', null=True, blank=True) created_on = models.DateTimeField(blank=True, auto_now_add=True) userUpVotes = models.ManyToManyField(User, blank=True, related_name='threadUpVotes') userDownVotes = models.ManyToManyField(User, blank=True, related_name='threadDownVotes') votes = models.IntegerField() def html(self): DiscussionTemplate = loader.get_template("inclusions/discussionTemplate") return DiscussionTemplate.render(Context({ 'discussion': self, 'replies': [reply.html() for reply in self.replies.all().order_by('-votes')] })) def _find_users_who_have_voted(self): user_list = [] for user in self.userDownVotes.all(): user_list.append(user.id) for user in self.userUpVotes.all(): user_list.append(user.id) return user_list users_voted = property(_find_users_who_have_voted) </code></pre> <p>and my view is called like this</p> <pre><code>&lt;ul&gt; {% for discussion in discussions %} {{ discussion.html }} {% endfor %} &lt;/ul&gt; </code></pre> <p>and the template</p> <pre><code>&lt;li&gt; &lt;small&gt; ({{ discussion.votes }} votes) {% if user_id not in discussion.users_voted %} user not in list! {% endif %} &lt;/small&gt; &lt;strong&gt;{{ discussion.message }}&lt;/strong&gt; {% if replies %} &lt;ul&gt; {% for reply in replies %} {{ reply }} {% endfor %} &lt;/ul&gt; {% endif %} </code></pre> <p></li></p> <p>the value 'user_voted' returns a list of user ids who has voted on this discussion.</p> <p>I want to see if the request.session['user'].id value is inside this list</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload