Hi i got a question lets say i got this models:
class Site():
site_name = charfield
class Sample():
site = foregeinkey
state = decimalfield
sample_date = datefield
and i need to assembly a table like this:
| site_name | latest_sample |
| site1 | 150 |
searching in the documentation an the internet link1 link2 i found annotate for when i need to adding some other characteristics to a query set and my new query is something like:
class ApiGetListOfSites(View):
def get(self, request, format=None):
objList = Site.objects.annotate(
date_sample=Max('sample__sample_date'),
valor_estado=F('sample__state')
)
json = serializers.serialize('json', objList)
return HttpResponse(json, content_type='application/json')
i got the problem that i retrieve repeated objects and no new columns in the json. some one con help me with some suggestions on how i can do this.
Ps i think if i write the query in raw SQL i can used with the raw property of django models.