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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:11:19+00:00 2026-05-12T20:11:19+00:00

Here is a related manager I wrote: class PortfolioItemManager(models.Manager): use_for_related_fields = True def extended(self):

  • 0

Here is a related manager I wrote:

class PortfolioItemManager(models.Manager):

    use_for_related_fields = True

    def extended(self): 

       return self.extra(select = {'current_price':'current_price', 'current_value':'current_price*quantity', 'gain':'current_price*quantity - cost'},
                      tables = ['pm_core_contract', ],
                      where = ['pm_core_contract.id = pm_core_portfolioitem.contract_id', ]
               )

Here are the results that stumps me:

In [10]: PortfolioItem.objects.extended()
Out[10]: []
In [11]: PortfolioItem.objects.extended().count()
Out[11]: 402

Result from count() is correct. What am I missing here?

EDIT: The generated SQL is correct and can be executed against the db directly.

EDIT2: The issue stems from the last 2 select arguments, which feature arithmetic operations.

  • 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-12T20:11:19+00:00Added an answer on May 12, 2026 at 8:11 pm

    I think I have just figured out the problem. Thanks go to Alex, whose comment has sparked the idea:

    The PortfolioItem model has the properties current_value and current_gain, which I have been trying to replace with calculated SQL fields. It was my mistake to name one of the extra() method’s select fields ‘current_value’ without removing the property, as that led to the model having two fields with the same name. When I did away with that overlapping, everything became OK. Lesson is learned.

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

Sidebar

Related Questions

A related post here pretty much established reflection in Java as a performance hog.
Related: see here I've got this command: exec((wget -O http://domain/file.zip && mysql -u user
Please see here for a related question . However, char goes to 0xffff (or
My initial question was here and was related to the postgres backend. Postgres subquery,
I'm stuck with another coordinates related query here. I have a number of CSV
I often see people asking XML/XSLT related questions here that root in the inability
I'm building a custom autoloader based on Zend Framework's autoloading (related question here ).
Here are two questions related to modifying the data source for strongly typed dataset
Here is a question not directly related to programming. Being fed up with Microsoft
This is slightly related to the question asked here yet the answer does not

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.