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 9176395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:06:07+00:00 2026-06-17T17:06:07+00:00

Sorry about the strange title, but I couldn’t explain the situation in a few

  • 0

Sorry about the strange title, but I couldn’t explain the situation in a few words. Let me articulate:

I have a Jobs model whose objects I show in a template. Against each job, I also want to show if the user has already applied for that job.

I have these models

class Job(models.Model):
    is_valid = models.BooleanField()
    description = models.CharField()
    def has_user_applied(self, user):
        return jobapplication_set.filter(applicant=user).exists()

class JobApplication(models.Model):
    applicant = models.ForeignKey(User)    
    job = models.ForeignKey(Job)
    cover_letter = models.CharField()

And a view in which I fetch all the Jobs:

 jobs = Job.objects.filter(is_valid=True)
 return HttpResponse( ... {'jobs': jobs} ... )

And a template in which I list them:

 {% for j in jobs %}
 {{ j.description }} {% if j.has_applied %} (You've already applied) {% endif %}
 {% endfor %}

However the “has_applied” function takes “user” as argument and passing arguments in templates is not allowed.

Now I have two issues:

Can I create a “context” so that some functions can assume that a particular user is in question rather than it being passed explicitly and limiting its usage in templates? If it is not possible, what is the elegant way of annotating this information in the model objects in the views?

Secondly, even If I’m able to do this, for each Job object, I still have to execute a separate query to determine if user has already applied. I know this is possible in raw SQL using outer joins, but can I do it using django’s ORM?

  • 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-06-17T17:06:08+00:00Added an answer on June 17, 2026 at 5:06 pm

    Easiest and most verbose way of doing it will be just:

    view

    jobs_applied_by_user = set(JobApplication.objects
                                             .filter(applicant=user)
                                             .distinct()
                                             .values_list('job', flat=True))
    

    template

    {% for job in jobs %}
        {% if job.pk in jobs_applied_by_user %}
            …
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(Sorry about the title, couldn't think of how to explain it) So I have
Sorry about the strange title. I really have no idea how to express it
Sorry about the long and convoluted title, but I couldn't summarize it better. I
Sorry about the vague question title, but I have these typedefs here: typedef std::list<AnimationKeyframe>
Sorry for the strange title. Here is my situation. I have a table of
Sorry about the strange title, I honestly tried to make it more precise but
Sorry about the strange title, but I am having a small issue if the
Sorry about a vague title, but here's what i am trying to do. I
Sorry about the title, I couldn't think of a better way to describe the
Sorry about the extremely vague question title (any suggestions for improvements welcome) I have

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.