Answer the question
In order to leave comments, you need to log in
Django how to properly return a list of objects?
Good evening, there is a field in the data project model of the JSONField type.
class Project(models.Model):
name = models.CharField(max_length=30)
projecttype = models.CharField(max_length=20, choices=TYPE_PROJECT, default=FILM, blank=False)
cgtype = models.CharField(max_length=20, choices=CG_TYPE, default=REALISTIC, blank=False)
currency = models.CharField(max_length=11, choices=CURRENCIES, default=USD)
customer = models.ForeignKey(Customer, on_delete=models.CASCADE)
data = JSONField(default=
[
{
"sequences":
[
{
"name": "",
"shots":
[
{
"name": ""
}
]
}
]
}
]
)
def __str__(self):
return self.name
path('api/list_projects/<int:user_id>', ProjectsView.as_view()),
class ProjectSerializer(serializers.ModelSerializer):
class Meta:
model = Project
fields = ('id', 'customer', 'name', 'projecttype', 'data')
class ProjectsView(generics.ListAPIView):
serializer_class = ProjectSerializer
def get_queryset(self):
user = self.kwargs["user_id"]
user_account = UserAccount.objects.get(user=user)
customer = Customer.objects.get(useraccount=user_account)
projects = Project.objects.filter(customer=customer)
return projects
'JSONField' object has no attribute '_get_val_from_obj'
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question