1π
β
In my case, having one class method at model level.
@property
def documents(self):
return [{
'name':doc.name,
'path':doc.path.name,
} for doc in self.documents.all()]
and i am using a related_name
on documents
on last line.
problem
earlier, I was using documents
as the method name which is also related_name
solution
you can not use related_name
as your method name.
so use any other name
π€Jamil Noyda
22π
You need to perform a query to get serializable data, when you have a relationship for example you can do something like this:
my_object.relatedmodel_set # This a RelatedManager
But if you do:
my_object.relatedmodel_set.all() # This is queryset
π€Gocht
- Unsupported lookup 'istartwith' for CharField or join on the field not permitted
- How to have Accent-insensitive filter in django with postgres?
- Drawing graphs in Django
Source:stackexchange.com