Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1036533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:43:14+00:00 2026-05-16T14:43:14+00:00

I have the following models: class Post(models.Model): message = models.TextField() (etc.) class UserProfile(models.Model): user

  • 0

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’d like to render a list of posts along with a “follow” or “unfollow” link so that the current user can decide whether to follow a given post. In a world where I could use arguments in Django templating, I’d 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 can’t do that. And I can’t make a zero-argument, template-callable method on any of these models, because they all need to know at least one other argument to answer the question whether a given PostFollow row exists in that table.

I’m happy to write a templating extension, but before I bring out the big guns, is this an appropriate case for doing so? Or is there a more Djangoesque solution?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T14:43:15+00:00Added an answer on May 16, 2026 at 2:43 pm

    Template filters are not big guns:

    # your_app/templatetags/following.py 
    
    from django import template
    register = template.Library()
    
    @register.filter
    def is_followed_by(post, user):
       return post.is_followed_by(user)  
    

    and then:

    {% load following %}
    ...
    {% if post|is_followed_by:user %} ... {% endif %}
    

    You can also put all logic in template filter, remove ‘post.is_followed_by’ method and use the filter instead of model method just like any other function, @register.filter decorator doesn’t harm the decorated function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 507k
  • Answers 507k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You could use INSERT IGNORE directly, or REPLACE - I'm… May 16, 2026 at 3:54 pm
  • Editorial Team
    Editorial Team added an answer As far as I know, for most scenarios, you can… May 16, 2026 at 3:54 pm
  • Editorial Team
    Editorial Team added an answer $('#zip-input').keyup(function(){ if($(this).val().length == 5) { //do your stuff here }… May 16, 2026 at 3:54 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have the following model in Django: class Bout (models.Model): fighter_1 = models.ForeignKey(Fighter, related_name=bout_fighter_1)
I have a model such as the following: class Item(models.Model): name = models.CharField(max_length=150) created
Consider the following models: class Person(models.Model): name = models.CharField(max_length=128) class Group(models.Model): name = models.CharField(max_length=128)
I am doing an user crud in spring-mvc. My model has the following properties:
I have a Registaration page with the following fields Email, Confirm Email, Password and
I'm using the following script to post to and endpoint, it's hitting the breakpoint
I have a class Foo with a field UpdateMe of type Confirmation as described
I have a strange behaviour on my Django/PostgreSQL system. After saving a model object
I just installed the plugin for Paperclip and I am getting the following error
I saw a similar post that was trying to do this same thing with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.