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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:17:40+00:00 2026-06-04T04:17:40+00:00

I am using Django models abstract base class to generate my website menus from

  • 0

I am using Django models abstract base class to generate my website menus from the db. My models look like this:

# ABSTRACT MENU 
class Menu(models.Model):
    position = models.IntegerField("Item Position", max_length=2, unique=False)
    title_en = models.CharField("Title (English)", max_length=50)
    title_es = models.CharField("Titulo (Español)", max_length=50)
    url_en = models.URLField("url (English)")
    url_es = models.URLField("url (Español)")       

    def __unicode__(self):
        return self.title_en

    class Meta:
        abstract = True

# top (main) menu ---> inherits from MENU
class MainMenu(Menu):
    class Meta:
        verbose_name_plural = "Menu Items"  

# submenu - for drop downs ---> inherits from MENU
class SubMenu(Menu):
    main_menu = models.ForeignKey(MainMenu, null=True, blank=True)
    class Meta:
        verbose_name_plural = "Sub Menu Items"

Then for the menus I do this:

menu_items = MainMenu.objects.all().select_related().order_by('position')

This is fine, and generates the main menu items ordered by position. However, the submenu items are not ordered. How can I make sure that the submenu items are ordered by position too?

  • 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-04T04:17:42+00:00Added an answer on June 4, 2026 at 4:17 am

    Have you tried defining the order in your model’s Meta class? As long as you are okay with position being the default order in every case it’s not explicitly overridden (which can have performance impacts for large queries) that should remove the need to use .order_by() at all. I haven’t tried this for your specific case, though, so let me know if it doesn’t work.

    Edit: also consider looking at order_with_respect_to for related models

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

Sidebar

Related Questions

I'm using django.contrib.admin in one of my apps. my models: class Gallery(models.Model): location =
Here is a Django model I'm using. class Person(models.Model): surname = models.CharField(max_length=255, null=True, blank=True)
Using Django 1.1.1 In models.py: class Site(models.Model): name = models.CharField(max_length=50) class SiteMonth(models.Model): site =
Ok, so I have a model like this: class Airplane(models.Model): tail = models.ForeignKey(Tails) wheel
Consider the following django model from django.db import models from django.contrib import auth class
class BaseCommentAbstractModel(models.Model): An abstract base class that any custom comment models probably should subclass.
I want to generate a list using my django model say I have these
I have multiple Django models that reference a model using foreign keys as such:
I'm using JSONField in some of my Django models and would like to migrate
I'm using Django 1.2. I would like to make a model with 3 fields,

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.