here is views.py
if request.is_ajax():
minpricestore = list(StoreProduct.objects.filter(product__id=productobj).values_list('store__StoreName' , flat=True).annotate(Min('price')))
print minpricestore
minprice = list(StoreProduct.objects.filter(product__id=productobj).values_list('price' , flat=True).annotate(Min('price')).order_by('price'))
print minprice
minId = list(StoreProduct.objects.filter(product__id=productobj).values_list('store__id' , flat=True).annotate(Min('price')).order_by('price'))
print minId
data = {
'minpricestore' : minpricestore ,
'minprice' : minprice ,
'minId' : minId
}
JsonResponse(data)
here is the ajax script
<script type="text/javascript">
function sendProduct(event, productId) {
event.preventDefault();
var data = { productId : productId };
// Send productId as query param of url
$.ajax({
type: "GET",
url: "{{instance.get_absolute_url}}",
data: data,
success: function(data) {
alert(data.minprice)
},
error: function(response, error) {
alert(error);
}
});
}
</script>
here is the queryset
minpricestore : [u'z store']
minprice: [1999]
minId:[1]
when i console.log it says undefined
ajax is working fine but unable to display the queryset.I get undefined when using alert.what can i do to to display the above queryset? Thanks in Advance