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

The Archive Base Latest Questions

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

I have a queryset in my django view. I would like to change the

  • 0

I have a queryset in my django view.

I would like to change the position of one of the item in order it to be the first element of the queryset.

Any idea on how to do that?

EDIT:

I have a queryset:

   qs = UserProfile.objects.filter(myfilter=whatever)

I know that inside this queryset I have:

   specific_user.userprofile

What I want to do is to put the user.userprofile in first position into my queryset because I use this queryset in a loop in my template:

    {% for i in qs %}
    <div> i.name </div>

And I want to be sure that the first name of the list is the name of the specific_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-14T17:06:16+00:00Added an answer on June 14, 2026 at 5:06 pm

    QuerySet objects in Django are abstract representations of the result of database queries. Generally speaking, it represents SQL that might later be executed when specific objects from the queryset are requested, but until that happens, no queries are executed. So you can’t really think of a queryset like a list, which might be arbitrarily reordered. You can request the objects in your queryset to be sorted using its order_by method, so if you want a particular object to come first, it must have some sortable attribute on the DB side of things by which it can be ordered. This could be a column or a value calculated from its columns using F expressions.

    But, for your needs, it seems like you could just make a list of your queryset in your view:

    profiles = [specific_user.userprofile] + [profile for profile in UserProfile.objects.filter(myfilter=whatever).exclude(id=specific_user.userprofile.id)]
    

    Add that to your context and iterate over it instead of the original queryset in your template.

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

Sidebar

Related Questions

I have a django view which uses a template to display a long queryset
I have a Django Queryset object called data containing string keys and float values.
I have a list of objects from a django queryset, e.g. my_list = MyObject.objects.filter(variable=something)
I have a question about django content_types In the example of filtering a QuerySet
I have a model that looks like this: from django.db import models from django.contrib.auth.models
I have a pair of Django models with a foreign key, one of which
I have a handful of records that I would like to sort based on
I'm using Django 1.3, and would like to get an array of objects using
I have a generic list view in Django which returns around 300 objects (unless
I have a Django Model that implements a time range, like this: class Period(models.Model):

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.