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

displaying of foreignkey or onetoone fields data without database calls #16

Closed
EricOuma opened this issue Sep 13, 2023 · 1 comment
Closed
Labels
help wanted Extra attention is needed

Comments

@EricOuma
Copy link
Contributor

PROBLEM
Data on the list view that come from ForeignKey or OneToOne fields trigger database calls

SOLUTION
They should be displayed using the data fetched from typesense hence no database calls should be made.

@EricOuma EricOuma added the help wanted Extra attention is needed label Sep 13, 2023
@EricOuma
Copy link
Contributor Author

Avoiding this has been explained in the docs

We recommend displaying data from ForeignKey or OneToOne fields as string attributes using the display decorator to
avoid triggering database queries that will negatively affect performance
Issue #16.

Instead of this in the admin:

@admin.display('Genre')
def genre_name(self, obj):
    return obj.genre.name

Do this:

@admin.display('Genre')
def genre_name(self, obj):
    # genre_name is field in the Collection. You can also store the object url as html
    return obj.genre_name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant