I'm trying to retrieve a list from django class based views and i'm getting the below output in my response
[{},{}]
The model currently has two items in it.
below is my views.py
class CategoryList(generics.ListCreateAPIView):
renderer_classes = (JSONRenderer,TemplateHTMLRenderer,BrowsableAPIRenderer)
template_name = 'create.html'
queryset = Category.objects.all()
serializer_class = CategorySerializer
models.py
class Category(models.Model):
category = models.CharField(max_length = 100)
below is my ajax call:
function getcategories(){
$.ajax({
type: 'GET',
url: 'http://127.0.0.1:8000/billing/categories',
contentType: 'application/json',
crossDomain:true,
success : function(json){
for (var i = 0; i < json.length; i ++){
$('#category-row').append('<td>'+json[i].category + '</td>');
console.log('success');
console.log(json.length);
}
},
error : function(){
console.log('there was an error with category-get');
}
});
};
where am I going wrong?