I have the following models:
class Post(models.Model):
message = models.TextField()
(etc.)
class UserProfile(models.Model):
user = models.ForeignKey(User, unique=True)
(etc.)
class PostFollow(models.Model):
post = models.ForeignKey(Post, related_name='follower_set')
follower = models.ForeignKey(UserProfile, related_name='follower_set')
creation_date = models.DateTimeField(auto_now_add=True)
an_arbitrary_score = models.IntegerField(default=0)
(etc.)
class Meta:
unique_together = ('post', 'follower',)
In my template, I would like to display a list of messages along with a follow or unfollow link so that the current user can decide whether to follow the given message. In a world where I could use arguments in Django templates, I would do something like this:
{% for post in post_set %}
<...stuff...>
{% if post.user_is_following user %}unfollow{% else %}follow{% endif %}
<...more stuff...>
{% endfor %}
However, I cannot do this. And I cannot make an argument method with a null argument that can be used for any of these models, because they all need to know at least one other argument in order to answer the question whether this PostFollow row exists in this table.
, , ? Djangoesque?