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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:14:17+00:00 2026-05-26T05:14:17+00:00

Designing code to handle transfers of objects called contractBundles. Have this in the models.py

  • 0

Designing code to handle transfers of objects called “contractBundles”. Have this in the models.py in a “contract” app:

class contractBundleManager():
 #   def trade(self, buyer, seller, amount):
     def add (self, user=pgamedb_models.Player, contractName=str, amount=float):
         contractList = contract.objects.all()
         for c in contractList:
             if contractName == c.contractText:
                 user.money = user.money - (amount * c.value)
                 return self.create(contract=c, volume=amount, owner=user)

class contractBundle(models.Model):
    objects = contractBundleManager()

    contract = models.ForeignKey('contract')
    volume = models.FloatField()
    owner = models.ForeignKey(pgamedb_models.Player)

    def __str__(self):
        return '%10.2f x %s -> %s' % (self.volume, self.contract.shortName, self.owner.user.username)

Elsewhere, I want to let people purchase the bundles by pressing a button:

from contracts import models as cmodels
...
 if request.method == 'POST':
          ...
        elif 'Buy' in request.POST:
            [set up activeUser, polName, amount]
            cmodels.contractBundle.objects.add(user=activeUser, contractName=polName, amount=amount)

Yet when the code calls the contractBundle.objects.add() method, I get the following error:

AttributeError at [url]
'Manager' object has no attribute 'add'
Request Method: POST
Request URL:    [url]
Django Version: 1.3.1
Exception Type: AttributeError
Exception Value:    
'Manager' object has no attribute 'add'
Exception Location: ...views.py in [method], line 56
Python Executable:  /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
Python Version: 2.7.1

Any thoughts why this might be happening?

  • 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-26T05:14:17+00:00Added an answer on May 26, 2026 at 5:14 am

    There are a couple of things here that are wrong.

    Firstly, your manager class needs to inherit from models.Manager:

    class contractBundleManager(models.Manager):
    

    This is where all the code like create is defined.

    Also, it seems like a really bad idea to use classes/types as default values for function parameters. If you want to document what types a function needs, you should use a docstring.

    Edit after comment No, I’m not referring to the return statement or the way you’re calling self.create. I’m referring to the default values in the contractBundleManager.add method. You should never do this. If someone calls your method without passing the user parameter, the function will use the default value you have defined – which is a class. Classes in Python are mutable, so your function will actually modify the definition of the Player class.

    Really, this is not the way to show the correct types to call the function with. Leave out the default values, and use a docstring.

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

Sidebar

Related Questions

I have been tasked with designing my web services client code to use the
I'm designing classes for my application (network tool). I this base class: class Descriptor
I'm designing a method for an input handler class. Here is some pseudo code...
I have a Java class that looks like this: public class My_ABC { int
When designing a new system or getting your head around someone else's code, what
When designing user table what would be the must have fields from the security/user
When designing a collection class, is there any reason not to implement locking privately
Is there a commonly-accepted practice for designing java objects that are frequently loaded and
Please help with this error .... In the following code the get info function
One often reads how it's worth designing your code to avoid needing to make

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.