You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Bug found in list_filter construct.
I can't use my specific application in this bug report b/c it is corporate knowledge, but I will do my best to describe it with an analogous app.
Say I have a BookCase model, and it can contain many Book models. There are many BookCases.
Book models point to a specific BookCase. I also have an Author model, which points to a specific Book (we assume an author only writes one book here). A Book may have multiple Authors.
In summary, the whole system may look something like this:
fromApp.modelsimportBookCase# gets a specific book casecase=BookCase.objects.filter(identifier="whatever")[0]
# gets all the Books that point to this BookCasecase.books#--------------------------fromApp.modelsimportBook# gets a specific bookbook=Book.objects.filter(identifier="whatever")[0]
# gets the BookCase that this Book points tocase=book.case# gets the Authors that point to this bookauthors=book.authors#--------------------------fromApp.modelsimportAuthor# gets a specific Authorauthor=Author.objects.filter(identifier="whatever")[0]
# gets the gets the Book that this Author points toauthor.book# gets the BookCase that this Author's Book resides inauthor.book__case
Now, if I want to make a model report using this tool to list all authors across all books across all book cases and filter by bookcase, I construct the following:
fromApp.modelsimportBookCase, Book, Authorfrommodel_report.reportimportreports, ReportAdminfromdjango.utils.translationimportugettextclassAuthorData(ReportAdmin):
title=ugettext('Book Summary')
model=Bookfields= [
'book__case',
'book__identifier',
'book__title',
'identifier', # author ID in database'name', # author name'address', # author address'phone_number', # author phone
]
list_group_by= ( 'book__case',)
list_filter= ('book__case',) # HERE is the problemlist_order_by= ('name',)
type='report'exports= ('excel', 'pdf')
reports.register('AuthorData', AuthorData)
When rendering the page, I expect that filter would be a list of BookCases, but instead it is a list of Books. Furthermore, upon selecting a Book in that filter and clicking "Get results", an error is thrown saying there is no BookCase matching the filter value. I suspect this is because the parameter for that filter wants a BookCase object, but a Book is given instead, and there's a type mismatch.
The text was updated successfully, but these errors were encountered:
For now, in my real project, I've simply added fields that reference the parents a few hierarchical steps up. It's a temporary solution for now, but not ideal; the database just got one column larger.
Bug found in list_filter construct.
I can't use my specific application in this bug report b/c it is corporate knowledge, but I will do my best to describe it with an analogous app.
Say I have a BookCase model, and it can contain many Book models. There are many BookCases.
Book models point to a specific BookCase. I also have an Author model, which points to a specific Book (we assume an author only writes one book here). A Book may have multiple Authors.
In summary, the whole system may look something like this:
Functions are in place to do the following:
Now, if I want to make a model report using this tool to list all authors across all books across all book cases and filter by bookcase, I construct the following:
When rendering the page, I expect that filter would be a list of BookCases, but instead it is a list of Books. Furthermore, upon selecting a Book in that filter and clicking "Get results", an error is thrown saying there is no BookCase matching the filter value. I suspect this is because the parameter for that filter wants a BookCase object, but a Book is given instead, and there's a type mismatch.
The text was updated successfully, but these errors were encountered: