Skip to content
Advertisement

Load data from model in view.py Django

I just started with Django and Python and I still don’t understand it very well. Would it be possible to access all the information stored in Persons, showing also orderstext and archivename, I can’t manage to do it :( my idea is to get all the information and save it as JSON, but I’m not getting the info from orderstext and archivename, it would be great if someone could show me the right way.

models.py

JavaScript

views.py

JavaScript

urls.py

JavaScript

JSON Response

JavaScript

Advertisement

Answer

You can annotate..[Django-doc] the clients queryset with the orderstext and archivename along side F-expressions..[Django-doc] like this:

JavaScript

Although instead of using values I highly recommend using something like DRF serializers..[DRF-doc] to handle serialization of your data.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement