Rudenate3
Rudenate3

Reputation: 1901

Updating a queryset

I'm trying to update columns with new information but I am getting the error: "'instancemethod' object is not iterable" and I can't figure out why.

The error happens when this function is called:

def update():
tests = Stock.objects.all
for test in tests:
    tick = test.ticker
    mo2 = get_dividend_per_share(tick)
    moy = get_dividend_yield(tick)
    mo3 = 1 * (Decimal(moy) / 100)
    mop = get_price_earnings_growth_ratio(tick)
    mod = Stock(price=mo, divps=mo2, divpd=mo3, peg=mop)
    mod.save()

I am relatively new to Django, am I going about this all wrong?

Upvotes: 1

Views: 285

Answers (1)

Yuval Adam
Yuval Adam

Reputation: 165182

Just a small typo, you missed the function call:

tests = Stock.objects.all()

If you prod around in an interactive shell you can see that:

>>> type(Stock.objects.all)
<type 'instancemethod'>

while invoking the all() method will return an iterable object, namely a Django QuerySet.

Upvotes: 3

Related Questions