On Tue, Sep 1, 2009 at 3:50 AM, neridaj<[email protected]> wrote:
>
> I'm trying loop over a query set in the example.html template of the
> simple project demo but I'm getting a "Caught an exception while
> rendering: 'function' object is not iterable" error and don't
> understand why. I ran type to make sure I'm returning a QuerySet
> object which I am: <class 'django.db.models.query.QuerySet'>.
>
> simple/localsite/models.py
>
> from listeners import veto_for_non_members
> from satchmo_store.shop import signals
> from django.core.signals import request_finished
> from utils import my_callback
>
> signals.satchmo_cart_add_verify.connect(veto_for_non_members,
> sender=None)
> request_finished.connect(my_callback, sender=None)
>
>
>
> simple/localsite/utils.py
>
> def my_callback(sender, **kwargs):
>    user = threadlocals.get_current_user()
>    user = user.username
>    user_products = ProductAttribute.objects.filter(value__exact=user)
>    print type(user_products)
>

You aren't returning anything here. Add "return user_products" to the
end of the function or do anything with user_products. As it is now,
the queryset simply gets lost somewhere.

>
>
> simple/localsite/views.py
>
> from utils import my_callback
>
> def example(request):
>    user_products = my_callback
>    ctx = RequestContext(request, {'user_products' : user_products })
>    return render_to_response('localsite/example.html', ctx)
>

I'm quite sure you cannot pass a function into a template. This only
works for functions / methods attached to objects. {% for i in
obj.function %} might work, {% for i in function %} will not.

Write user_products = my_callback()



It seems you are quite confused though. What is it you want to do? It
makes no sense to use the same function (my_callback) as a handler for
request_finished and inside a view function.


Matthias



-- 
FeinCMS Django CMS building toolkit: http://spinlock.ch/pub/feincms/

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Satchmo users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/satchmo-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to