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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:39:38+00:00 2026-05-24T11:39:38+00:00

The error: TemplateSyntaxError at /some/location Caught DatabaseError while rendering: more than one row returned

  • 0

The error:

TemplateSyntaxError at /some/location
Caught DatabaseError while rendering: more than one row returned by a subquery used as an expression

The model:

class Price(models.Model):
    supermarket = models.ForeignKey(SuperMarket)
    product = models.ForeignKey(Product)
    price = models.DecimalField(max_digits=6, decimal_places=2)

The query:

def costs_of_product(product, supermarkets):
    filter1 = Price.objects.filter(product=product)
    return filter1.filter(supermarket__in=supermarkets)

while the result of productList is the result of a call of costs_of_product.

The template:

<ul>   
{% for pr in productList %}
    <li>{{ pr.supermarket }}: {{ pr.price }} € </li>
{% empty %}    
    <li>No products are available.</li>
{% endfor %}
</ul> 

The question:
Why the aforementioned error is displayed at the first line of for in the template?

EDIT: Following the comment of amateur, I added this line in the view (none of the above snippets).

supermarkets = [supermarket.id for supermarket in supermarkets]

and then I called costs_of_product() and it worked! What is very curious is that when I move this line in the body of the function costs_of_product(), it does not work!

  • 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-24T11:39:39+00:00Added an answer on May 24, 2026 at 11:39 am

    Try to use Q. Something like this:

    from django.db.models import Q
    
    def costs_of_product(product, supermarkets):
        filter1 = Price.objects.filter(Q(product=product) & Q(supermarket__in=supermarkets))
        return filter1
    

    You use filter on list, so this can possiibly cause an error.

    As for place – it’s because Django try to render objects you got (and yes, Django got something from your function), but can’t do it.

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

Sidebar

Related Questions

An error has occurred while establishing a connection to the server. When connecting to
Error while running an installed Windows Service on dedicated Server I installed my windows
Error message: fatal: git checkout: updating paths is incompatible with switching branches/forcing How to
This error just started popping up all over our site. Permission denied to call
The error I'm getting: in /Users/robert/Documents/funWithFrameworks/build/Debug-iphonesimulator/funWithFrameworks.framework/funWithFrameworks, can't link with a main executable Cliff notes:
This error seems to just pop up now and again. It is not restricted
This error message appears on a colleague's machine when he tries to launch a
Fatal error: Allowed memory size of 31457280 bytes exhausted (tried to allocate 9828 bytes).
Parser Error Message: The entry 'SiteSqlServer' has already been added. Source Error: Line 23:
Compiler error CS0283 indicates that only the basic POD types (as well as strings,

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.