python - saving search results as text instead of list -
i using django 1.8 , working on blog application. when search tweets( name instead of posts) , want save search results obtained after querying database, text instead of list. view function below:
def search(request): query = request.get.get('q','') if query: qset = ( q(text__icontains=query) #q(hashes__icontains=query) #q(artist__icontains=query) ) results = tweet.objects.filter(qset).distinct() else: results = [] number_of_results = len(results) search_item = query returned_items = [] res in results: text = res.text returned_items.append(text) returns = returned_items[:] search = search(search_item=search_item,returns=returns) search.save() context = {'query':query,'results':results,'number_of_results':number_of_results,'title':'search results '+request.get.get('q','')} return render_to_response("tweets/search.html",context,context_instance=requestcontext(request))
also, snapshot of search table in database shown below:
please me out friends.
you should join returned list using comma separted values. return string.
returns = ', '.join(returned_items)
Comments
Post a Comment