[Solved]-<django.db.models.fields.related.RelatedManager object at 0x7ff4e003d1d0> is not JSON serializable

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.

The related_name attribute specifies the name of the reverse relation from the User model back to your model.

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

Leave a comment