Skip to content
This repository was archived by the owner on Aug 19, 2025. It is now read-only.

Add Model and Queryset .all() as_dict support#76

Closed
blue-hope wants to merge 1 commit intoencode:masterfrom
blue-hope:master
Closed

Add Model and Queryset .all() as_dict support#76
blue-hope wants to merge 1 commit intoencode:masterfrom
blue-hope:master

Conversation

@blue-hope
Copy link

As-Is:
ORM model does not support its own dictionary serialize method

To-be:
ORM model can be serialized to dict like this:
await User.objects.get(id=1).as_dict()
or Queryset.all() that returns ORM model objects' list can be serialized to dict like this:
await User.objects.all().as_dict()

  • I run lint script


async def as_dict(self):
return {
column.name: getattr(self, column.name) for column in self.__table__.columns
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here's class model's new as_dict method

@blue-hope blue-hope marked this pull request as draft September 30, 2020 09:22
@blue-hope blue-hope marked this pull request as ready for review September 30, 2020 09:23
@xloem xloem mentioned this pull request Aug 9, 2021
@aminalaee aminalaee closed this Nov 23, 2021
@YuriFontella
Copy link

Hello, was this truly implemented?
I see that the pull request was closed, but this doesn't work.

orm 0.3.1

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants