MY VIew
def cargar_categorias(request):
data = serializers.serialize("json", MyModel.objects.all())
return HttpResponse(data, mimetype='aplication/json')
response json
[{"pk": 8, "model": "MyModel.MyModel", "fields": {"celular": "234342342", "logo": "recetas/aurelio.jpg", "tipo": 1, ....
but the field "tipo" is a foreign Key, I need recover the value of this field and not the id (1)
My Jquery code
$.ajax({
type: "GET",
contentType: "application/json; charset-utf-8",
dateType: "json",
url: "/cargar_categorias",
success: function(response){
var i=(response.length-1)-6;
for( i;i<=(response.length-1);i++){
$('#locations').append("<li data-celular='"
+ response[i].fields.celular +"' data-tipo='"
+ response[i].fields.tipo +"'><img href=#"
+ response[i].fields.logo +" src='/media/"
+ response[i].fields.logo +"'/></li>");
}
}
});
I think can use select_related() but not work, or response[i].fields.tipo.nombre or .... I don't now, please help me, this going crazy, sorry my english