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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:16:42+00:00 2026-05-22T19:16:42+00:00

My model: … class Bild(models.Model): album = models.ForeignKey(Album) slot = models.IntegerField() bild = models.ImageField(upload_to=’bilder’,

  • 0

My model:

...
class Bild(models.Model):
    album = models.ForeignKey(Album)
    slot = models.IntegerField()
    bild = models.ImageField(upload_to='bilder', null=True)
    untertitel = models.CharField(max_length=200, null=True)
    def __unicode__(self):

My view:

def album_bild(request, album_id, bild_id):
    album_id = int(album_id)
    bilder = Bild.objects.filter(album__id = album_id).order_by('slot')
    ....

When I iterate through “bilder” in the template, I can see that the filter() did work but the objects are still ordered by the pk instead of the “slot”.

Is there a problem with my usage of filter() and order_by()?

EDIT: I guess i should add that everything works fine in the shell. So maybe the error is in the template…?

{% for bild in bilder %}
    <li 
    {% ifequal bild.slot bild_id %}
            class="active" 
    {% endifequal %}
    onclick="window.location.href='/portfolio/{{ album_id }}/{{ bild.slot }}'"><div>{{ bild.slot }}</div></li>
{% endfor %}

{% for i in empties %}
    <li class="empty"></li>
{% 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-22T19:16:43+00:00Added an answer on May 22, 2026 at 7:16 pm

    I’ve done lots of .filter().order_by() chains just as you have them there, and nothing jumps out to me as out of place. I’ve never tried to carry that ordering over to the template without further processing the objects though (usually iterate over them), so I wonder if the order_by() is lost as part of django’s lazy evaluation? Maybe try wrapping the filter().order_by() line in a list() to force evaluation there instead of it being put off till some later time?

    bilder = list(Bild.objects.filter(album__id = album_id).order_by('slot'))
    

    It is a shot in the dark, but quick enough to be worth a try.

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

Sidebar

Related Questions

Model: class ExpertLevel(models.Model): level = models.CharField(max_length=100) subject = models.ManyToManyField(Subject, blank=True, null=True) class Expert(models.Model): appuser
class Tag(models.Model): name = models.CharField(maxlength=100) class Blog(models.Model): name = models.CharField(maxlength=100) tags = models.ManyToManyField(Tag) Simple
Example model: class Contestant(models.Model): first_name = models.CharField(max_length=255) last_name = models.CharField(max_length=255) email = models.EmailField() ...
Model and ModelForm in django project are defined like this : class Consumption(models.Model): date=models.DateTimeField(default=datetime.now)
I have a rails model that looks something like this: class Recipe < ActiveRecord::Base
I have this Task model: class Task < ActiveRecord::Base acts_as_tree :order => 'sort_order' end
Model public class PdfPage { public IEnumerable<PdfPhoto> Photos { get; set; } } public
My model looks like this: public class SelectionItem : BaseEntity // BaseEntity ==> id,
Model : <?php class Blogm extends CI_Model{ function __construct() { // Call the Model
Model <?php class Tonguetwister extends AppModel { var $name = 'Tonguetwister'; //The Associations below

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.