I have a simple view that I want to respond to both ajax and regular HTTP requests. Simplified, it looks like this:
def tag_search(request, tag):
items = Item.objects.filter(tags__tagname__exact=tag)
if request.is_ajax():
return HttpResponse(serializers.serialize( json , items), mimetype= application/json )
else:
return render_to_response( mytemplate.html , locals())
The problem is that it isn t returning the values of the many to many relationships - just a list of the primary keys like:
[1, 2, 5]
I understand that I can t use select_related() to follow many to many relationships - can anyone provide me with a best practice for passing that information back, or an example?