Answer the question
In order to leave comments, you need to log in
Django, how to access a field in a queryset?
Good afternoon, there is a simple view
class ProjectsView(View):
def get(self, request, *args, **kwargs):
user = kwargs["user_id"]
user_account = UserAccount.objects.get(user=user)
customer = Customer.objects.get(useraccount=user_account)
projects = Project.objects.filter(customer=customer).values()
return JsonResponse(list(projects), safe=False)
Answer the question
In order to leave comments, you need to log in
QuerySet is a collection of elements, so your task is to get one element from the collection, and then get the attribute value of this element:
projects = Project.objects.filter(customer=customer).first()
if project is not None:
data = project.data
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question