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 Options._get_fields #2254

Merged
merged 1 commit into from
Jul 9, 2024
Merged

Add Options._get_fields #2254

merged 1 commit into from
Jul 9, 2024

Conversation

Viicos
Copy link
Contributor

@Viicos Viicos commented Jul 8, 2024

Although private, this method is pretty useful when inspecting models

def _get_fields(
self,
forward: bool = ...,
reverse: bool = ...,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could probably have an overload on reverse, I think if reverse=False, ForeignObjectRel can't be present in the return type

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

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

Do you have any real-life / opensource examples of using this method?

@Viicos
Copy link
Contributor Author

Viicos commented Jul 9, 2024

A github search shows some examples: https://github.com/search?q=%22_meta._get_fields%22&type=code

Otherwise, I'm mainly using it when I want to exclude/include forward/reverse relationships, as they are all included by default. However, filtering can also be done on the result of get_fields, so this is really up to you!

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

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

Thank you!

@sobolevn sobolevn merged commit bdb4b88 into typeddjango:master Jul 9, 2024
36 checks passed
@Viicos Viicos deleted the get-fields branch July 10, 2024 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants