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 to_field_name=slug on LocationForm.parent, update prepare_cloned_fields to handle it #2773

Merged
merged 1 commit into from Nov 9, 2022

Conversation

glennmatthews
Copy link
Contributor

@glennmatthews glennmatthews commented Nov 8, 2022

Closes: #2470

What's Changed

  • Added to_field_name="slug" on the LocationForm parent field so that the slug, rather than the PK, of the parent Location is used when auto-generating a slug for the new/edited Location. (Fix Child location's slug is autogenerated using parent's UUID rather than slug #2470)
  • By itself, this would reintroduce Editing a Location doesn't retrieve parent #2311, because prepare_cloned_fields (which is used to generate the query parameters that are used to pre-populate an edit form in various cases) always uses the PK of any foreign-key fields in the generated query parameters, and passing a PK in the query parameters when the form field expects a slug wouldn't work. Therefore, I extended prepare_cloned_fields to look up the associated edit form, and in the case where a FK model field has a form field with to_field_name defined, use that field from the related object instead of its PK.
  • Added a bit more exception handling in DynamicModelChoiceMixin.get_bound_field because I tripped over a ValidationError when initially exploring this issue.
  • Enhanced get_related_class_for_model to accept a model instance as a valid input.

image

TODO

  • Explanation of Change(s)
  • Added change log fragment(s) (for more information see the documentation)
  • Attached Screenshots, Payload Example
  • Unit, Integration Tests - there are currently no tests that I see for prepare_cloned_fields; I'll see about adding some
  • n/a Documentation Updates (when adding/changing features)
  • n/a Example Plugin Updates (when adding/changing features)
  • Outline Remaining Work, Constraints from Design

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Child location's slug is autogenerated using parent's UUID rather than slug
3 participants