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

  • Home
  • SEARCH
  • 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 8884179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:00:14+00:00 2026-06-14T21:00:14+00:00

I have a model: class ProjectBookmark(models.Model): user = models.ForeignKey(User) project = models.ForeignKey(‘Project’) say a

  • 0

I have a model:

class ProjectBookmark(models.Model):
    user = models.ForeignKey(User)
    project = models.ForeignKey('Project')

say a user is viewing a project, is there a way to somehow check if current project is in users bookmarks other than a nasty way I do this now via request context as bellow? Basically, users bookmarks are a list of projects and checked as

{% if current_project in current_user.bookmarks %}…

right from inside the template?

the_user = request.user
bookmarked_projects = list()
for b in ProjectBookmark.objects.filter(user = request.user):
    bookmarked_projects.append(b.project_id)
the_user.bookmarks = Project.objects.filter(id__in=bookmarked_projects)
return {'current_user':request.user}
  • 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-14T21:00:16+00:00Added an answer on June 14, 2026 at 9:00 pm

    For use directly in a template, the best way to go would be creating a custom template tag. Check out the template tag docs.

    As for the filtering code itself, it would be very helpful to provide related_name arguments to the ForeignKey fields in the model definition. For example:

    class ProjectBookmark(models.Model):
        user = models.ForeignKey(User, related_name="project_bookmarks")
        project = models.ForeignKey('Project', related_name="bookmarks")
    

    This way you could access a QuerySet object containing all the users bookmarks using request.user.project_bookmarks.all()

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

Sidebar

Related Questions

I have a model class like this: class Note(models.Model): author = models.ForeignKey(User, related_name='notes') content
I have a model: class Article(models.Model): text = models.CharField() author = models.ForeignKey(User) How do
I have this model: class Event_Category(models.Model): event=models.ForeignKey(Event,related_name='event_category') category=models.ForeignKey(Category,related_name='events') user=models.ForeignKey(User) in the view: magazie_cats=Event_Category.objects.filter(event=instance).order_by('category').distinct() return
Let's say I have a model class called Project, but instead of this: class
I'm newcomer in django, and here is question: I have model class: def Client(models.User)
I have a model class Article(models.Model): . . language = models.ForeignKey(Language, help_text=Select the article's
I have following model: class UserProfile(models.Model): User profile model, cintains a Foreign Key, which
I have django model: class UserProfile(models.Model): user = models.OneToOneField(User) #other fields When I create
I have a model: class Zone(models.Model): name = models.CharField(max_length=128) users = models.ManyToManyField(User, related_name='zones', null=True,
I have this model: class option(models.Model): warval = models.ForeignKey(war) caption = models.CharField(max_length=20) text =

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.