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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:16:56+00:00 2026-05-24T07:16:56+00:00

i have written these models in models.py: class User(models.Model): first_name = models.CharField(max_length=80) class Skill(models.Model):

  • 0

i have written these models in models.py:

class User(models.Model):
    first_name = models.CharField(max_length=80)

class Skill(models.Model):
    user = models.ForeignKey(User)
    title = models.CharField(max_length=80)
    level = models.IntegerField(default=3)

class Work(models.Model):
    user = models.Foriegnkey(User)
    work_name = models.CharField(max_length=80)
    salary = models.IntegerField()

now i want to get those Works from database which their users have a certain skill, and render a html with them. i write this code in views.py:

def show_works(request, skill):
    works = Work.objects.select_related().filter(user__skill__title=skill)
    return render_to_response("works.html", {'works':works})

but there is another thing i want to show in that html: i want to show first_name of the user of that work and his skills. i used select_related(), but i can only show first_name but i can’t reach user’s skills.

i want to write an optimal query to get the works and the other extra informations, like user and the skills of it user! like the code blow:
( i don’t want to hit database for every work to get its user’s skills )

template works.html:

{% for work in works %}
    
        {{work.work_name}}
        user is : {{work.user.first_name}}
        which has these skills:
        {% for skill in work.user.skill %}
             {{skill.title}} 
        {% endfor %}
    
{% endfor %}
  • 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-24T07:16:57+00:00Added an answer on May 24, 2026 at 7:16 am

    You’ll probably never look at this again, but I’ll try to answer it anyway.

    I would think that this should work:

    {% for skill in work.user.skill_set.all %}
        {{skill.title}}
    {% endfor %}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have models like this class Blog(models.Model): name = models.CharField(max_length=100) tagline = models.TextField() def
Here is the code I've written: models.py: class Name_overall(models.Model): rank = models.IntegerField() name =
I have some code written like so: class Invite(models.Model): STATE_UNKNOWN = 0 STATE_WILL_PLAY =
I have an Account model and a User model: class Account < ActiveRecord::Base has_many
I have the following model classes declared by SQLAlchemy: class User(Base): id = Column(Integer,
I have about 150 000 rows of data written to a database everyday. These
I have written a class to create and battle pokemon but I cannot figure
I have a tree structure of widgets e.g. collection contains models and model contains
I have a roles model in a rails app that I have written a
I have a search method written for my model Link. I've been able to

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.