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

Bugfix: PROTECTED with related_name='+' #6698

Closed
wants to merge 1 commit into from

Conversation

m3brown
Copy link
Contributor

@m3brown m3brown commented Jan 15, 2021

This PR is an attempt to resolve wagtail-nest/wagtail-modeladmin#30.

Changes in this PR:

  • Make adjustments to views.py to handle related_name="+"
  • Add test cases for ForeignKey and OneToOneField
  • Refactor some of the surrounded code to properly support cases where there are multiple "+" relationships
    • The old code would only pick one, since the keys in fields_map would conflict

Before submitting, please review the contributor guidelines https://docs.wagtail.io/en/latest/contributing/index.html and check the following:

  • Do the tests still pass? Yes
  • Does the code comply with the style guide? I ran flake8 on all the modified files
  • For Python changes: Have you added tests to cover the new/fixed behaviour? Yes
  • For front-end changes: Did you test on all of Wagtail’s supported browsers? N/A
  • For new features: Has the documentation been updated accordingly? N/A

@squash-labs
Copy link

squash-labs bot commented Jan 15, 2021

Manage this branch in Squash

Test this branch here: https://m3brownbugfix-model-admin-prot-sj546.squash.io

@m3brown m3brown force-pushed the bugfix-model-admin-protected branch from 7599cba to 6fc6d13 Compare January 15, 2021 23:23
@m3brown m3brown force-pushed the bugfix-model-admin-protected branch from 6fc6d13 to 16518d9 Compare January 16, 2021 16:44
if rel.on_delete == models.PROTECT:
if isinstance(rel, OneToOneRel):
try:
obj = getattr(self.instance, rel.get_accessor_name())
if rel.get_accessor_name() != '+':
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Arguably, the performance of both if and else OneToOneField implementations are similar, they're both a "get" operation, so we could potentially drop the if and use the else implementation all the time...

In contrast, for the implementation for ManyToOneFields, I assume a releated_name lookup is more efficient than doing a filter of the related model? In other words, I imagine leaving the if and else implementations makes sense for ManyToOneField.

@laymonage
Copy link
Member

Hello, I'm closing this as it's quite dated and we no longer accepting PRs for new ModelAdmin features in Wagtail as per wagtail/rfcs#85. If you'd like, you could create a new PR to the wagtail-modeladmin repository. If the bug fix is critical, we might consider backporting it to the Wagtail repo during the deprecation period. Thank you!

@laymonage laymonage closed this Jul 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

modeladmin PROTECTED with related_name="+"
3 participants