Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 1 commit into from

Conversation

blue-hope
Copy link
Member

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

@@ -285,6 +309,11 @@ def pk(self):
def pk(self, value):
setattr(self, self.__pkname__, value)

async def as_dict(self):
return {
column.name: getattr(self, column.name) for column in self.__table__.columns
Copy link
Member 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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants