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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:45:14+00:00 2026-06-07T02:45:14+00:00

This QuerySet (Let’s say Model model has 12 field): objects = Model.objects.filter(…) And this

  • 0

This QuerySet (Let’s say Model model has 12 field):

objects = Model.objects.filter(...)

And this template:

{% for object in object %}
<a href='{{ object.get_absolut_url }}'>Foo: {{ object.bar }}</a>
{% endfor %}

perform SQL query which gets unnecessary fields (every 12 fields + relations). I want Django to get only ‘bar’ field. How can I do this?

By the way I know about values() method, but as it returns dict, I can’t call Model methods such as get_absolute_url().

  • 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-07T02:45:15+00:00Added an answer on June 7, 2026 at 2:45 am

    You want to use only():

    objects = Model.objects.select_related().only(“bar”).filter(…)

    Keep in mind however if you limit too much of the data down and then use the objects in other ways you can actually cause the ORM to execute extra queries, so make sure to be using something like django-debug-toolbar to ensure you aren’t removing these unnecessary fields to only incur the hit of lots of unnecessary queries which is a worse situation.

    FYI you can also use defer() to list the fields you don’t want loaded if you want to think about it in the other direction.

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

Sidebar

Related Questions

Let's say I have a queryset of things Bill has worked on like this:
I have a ModelChoiceField in django forms: customField = forms.ModelChoiceField(queryset=MyModel.objects.filter(type=sometype)) But this queryset returns
employee = Employee.objects.filter('age' = 99) We assume this queryset is empty. If I use
employees = Employee.objects.filter(age=23, sex='female') This would return a queryset. If I assume this queryset
I have this QuerySet: brand = get_object_or_404(Brand, shortcut=shortcut) ads = Ad.objects.filter(mod__submodel__model__brand = brand).values('id') But
How do I create a dynamic field on a model? Let's say I'm writing
I have this path in my urls.py: archive_index_dict = { 'queryset': News.objects.filter(show=True), 'date_field': 'date',
This line works and returns the value that I'm looking for: logs = Log.objects.filter(filterURI=aFilter.uri).values()[0]['yk']
Let's say that I have a list of movie ids in a QuerySet in
This is in my urls.py: group_info = { 'queryset': Group.objects.all(), 'template_object_name': 'groups', 'paginate_by': 25,

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.