-
-
Notifications
You must be signed in to change notification settings - Fork 483
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
Access foreign key of historic instance from model methods #1314
Comments
Thank you for reporting this! I'm planning on changing the implementation of the historical models' In the meantime, however, could you try implementing one of the two methods detailed below? (This is from a draft change to the docs)
|
Problem Statement
When accessing the related object of a historic instance's foreign key from a model method such as
__str__()
, the related object is looked up in the main table, not the history, potentially resulting in aDoesNotExist
exception if that related object had been deleted.Example:
models.py
:./manage.py shell
:The culprit here is the
{self.owner}
inCar.__str__()
. If removed, no errors occur.Note that this affects the admin as well. Browsing the history of this instance shows the same error, and the entire history becomes inaccessible from the admin ui.
Describe the solution you'd like
Being able to access historic instances of related objects when accessed through historic instance of the main model, to avoid
DoesNotExist
errors.If that can be achieved implicitly, i.e. without any changes to the code above, that'd be great. But an explicit solution that would require modifying the code above would be OK, too. Right now, I can't tell from within the
__str__()
method whether the instance is current or retrieved from history, and if the latter, what's the history date.Describe alternatives you've considered
Explicitly adding code that solves the problem. However, it's unclear to me what such code would be either.
The text was updated successfully, but these errors were encountered: