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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:14:48+00:00 2026-05-19T00:14:48+00:00

I currently have a set of models that look similar to this contrived code:

  • 0

I currently have a set of models that look similar to this contrived code:

class Pizza(models.Model):
    price = models.FloatField()
    topping = models.ManyToManyField(Topping, through="PizzaToppings")

class Topping(models.Model):
    name = models.CharField(max_length=50)

class PizzaToppings(models.Model):
    class Meta:
        ordering=["order_to_add_topping"]

    pizza = models.ForeignKey(Pizza)
    topping = models.ForeignKey(Topping)
    order_to_add_topping = models.IntegerField()

My problem is that what happens when I attempt to access the toppings of a pizza in the order specified in the PizzaToppings ManyToMany extra fields table. Assume the pizza has cheese and ham, with the order_to_add_topping in the PizzaToppings data set to 0 and 1 respectively:

>>> pizza = Pizza.objects.get(pk=490)
>>> pizza.toppings.all()[0].name
'Ham'

That should say ‘Cheese’. I would have thought the RelationManager would have respected the ordering Meta class field, but it appears it doesn’t. So I guess accessing the name of the first topping added to the pizza shouldn’t be done with pizza.toppings.all()[0].name.

How should it be accessed? Is the problem with my model query or is it how I have my models set up?

  • 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-19T00:14:49+00:00Added an answer on May 19, 2026 at 12:14 am

    Your model is fine you just need to query the relationship since now you have a “through” relationship with extra fields. The relationship is created automatically as topping_relationship in your case, so your query should be:

    pizza.toppings.order_by('topping_relationship__order_to_add_topping')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently I have my entities working with models that look like: public class MyModel
I currently have this set up and working fine inside a users folder. RewriteEngine
I currently have my code set to disable the submit button when the field
I currently have a .htaccess file set up with this rule: RewriteRule ^([a-zA-Z0-9_-]+)$ user\.php?user=$1
Currently I have a site that is set up using a masterpage and a
Currently I have this: [SomeCustomAttribute] public string Name { get; set; } However, I
I have multiple classes that I need to map into 1 class: This is
I have been tasked with refactoring a project that currently uses an EAV model
I have a model that contains datefield . I'm trying to get query set
I have a model called Lines. On it I have a address class that

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.