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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:17:28+00:00 2026-05-27T17:17:28+00:00

I have a table called Tip and table called FavoritedTips . Users favorite Tips

  • 0

I have a table called Tip and table called FavoritedTips. Users favorite Tips in my app and the tip ID and user ID are added to the favoritedTips table.

class FavoritedTip(models.Model):
    tip = models.ForeignKey(Tip)
    user = models.ForeignKey(User)

I now need to put a star next to the tip when the tips appear in the list. But of course tips = Tip.objects.filter(list=list) doesn’t have a tip.favoritedtip column.

What’s the easiest thing to do in my template to know which tip has been favorited?

  • 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-27T17:17:29+00:00Added an answer on May 27, 2026 at 5:17 pm

    I presume you want to display a list of tips and for each one you need to know if this is a favorite of the current user.

    You can do it with a custom templatetag if you really want to do that at the template level, but you’d better build your data structure in the view :

    tips = Tips.objects.filter(my_filters)
    user_favorite_tips = request.user.favoritedtip_set.values_list('pk', flat=True)
    tips = [{'tip': tip, 
             'is_favorite': tip.pk in user_favorite_tips and True or False}
             for tip in tips]
    

    And then in your template :

    <ul>
    {% for tip in tips %}
        <li>{{ tip.tip.as_html }} 
            {% if tip.is_favorite %} <img src="star.png" />{% endif %}</li>
    {% endfor %}
    </ul>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have table called users , if i want to delete some user (User
I have a table called Users that has a column called deleted, a boolean
I have table of users called users and log table called ulog . Every
I have a table called user_details this table has got morethan 100k user details
I have table called users and I want to make an exact copy as
Have a table called user_products that contains a record for each product the user
I have table called stats . In am inserting yes or no in the
I have a table called OffDays, where weekends and holiday dates are kept. I
I have a Table called Product and I have the Table StorageHistory . Now,
I have a table called ApprovalTasks... Approvals has a status column I also 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.