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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:07:54+00:00 2026-05-23T07:07:54+00:00

My model has a def on it which returns a calculated field. In my

  • 0

My model has a def on it which returns a calculated field. In my template I’m displaying the fields of my model and my def calculated field displays fine too.

But when I use distinct() in the queryset then the def calculated field no longer appears in the template. Why?

Another question is that the foreign keys are now being displayed as their IDs instead of their unicode.

How can I get the calculated field to display and not have the ids but the usual unicode pull through. Is this possible using distinct()?

models.py

@property
def calculated_total(self):
    aggregated_cost = sum([m.total for m in Fee.objects.filter(contract=self.contract,grouping=self.grouping,\
                        party_incurring_fee=self.party_incurring_fee,\
                        party_paying_fee=self.party_paying_fee)])
    return aggregated_cost

views.py

calculated_subtotal_queryset = Fee.objects.values('party_incurring_fee', 'party_paying_fee', 'grouping').distinct()

context_dict = {
    'Subtotal' : calculated_subtotal_queryset,
}
return render_to_response('contract.html', context_dict)

contract.html

                {% for s in Subtotal %}
                <tr>
                    <td>{{ s.calculated_total }}</td>
  • 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-23T07:07:54+00:00Added an answer on May 23, 2026 at 7:07 am

    In the view you are passing a ValuesQuerySet to the template, therefore the loop in your template gets dictionaries instead of a regular queryset containing model-instances. I don’t understand your second question but most probably it has to do with the ValuesQuerySet again.

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

Sidebar

Related Questions

I have this model which has Image field to be uploaded. It has a
I have a model called MessagePerson which has the fields of details which depict
Specifically, I have a model that has a field like this pub_date = models.DateField(date
Java has generics and C++ provides a very strong programming model with template s.
In my UserProfile model I would like to have a function which returns either
I have a model called a voip_phone that has a an attribute schedule which
My model has quite a few boolean fields. I've broken these up into 3
I have a Rails model called Person which has database table columns for first_name
I have a model which has a method called 'has_voted'. It looks like this...
I have a Project model. This model has Days which are inlines . How

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.