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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:20:50+00:00 2026-06-17T10:20:50+00:00

This works in python IDLE class A: b = 0 def __init__(self, value): self.b

  • 0

This works in python IDLE

class A:
    b = 0

    def __init__(self, value):
        self.b = value

obj1 = A(1)
obj2 = A(2)
obj3 = A(3)
k = [obj1, obj2, obj3]
result = sum(i.b for i in k)
print str(result)

But this doesn’t work for django/python

from django.db import models

class Flatbar(models.Model):
    width = models.IntegerField()
    height = models.IntegerField()

    def Area(self):
        return self.width * self.height

class Section(models.Model):
    flatbars = models.ManyToManyField(Flatbar)

    def Area(self):
        return str(sum(f.Area for f in self.flatbars))

Why is this not working and how would I do this using a lambda function?

  • 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-17T10:20:51+00:00Added an answer on June 17, 2026 at 10:20 am

    The attribute for a ManyToManyField yields a manager, and you made Area a method.

    return str(sum(f.Area() for f in self.flatbars.all()))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Unless I'm mistaken, creating a function in Python works like this: def my_func(param1, param2):
Can somebody explain to me why this works (in Python 2.5) : class Foo(object):
When you start/stop a python cherrypy service (compiled with py2exe), this works fine When
i have the following code in a module called code_database.py class Entry(): def enter_data(self):
The code is like this: os.execlp('python', 'python', 'child.py', #other args#) # this works os.execlp('python',
this is my code on python 3.2.3 IDLE: numbers = [] numbers = input((Enter
I'm trying to understand multiprocessing in python. from multiprocessing import Process def multiply(a,b): print(a*b)
{x for x in range(10)} works perfectly on IDLE, but when I try this
This code works in IDLE but not in the commandline. Why the difference? poem
Possible Duplicate: Why doesn't this division work in python? A simple problem I'm having

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.