Add to_field_name=slug on LocationForm.parent, update prepare_cloned_fields to handle it #2773
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes: #2470
What's Changed
to_field_name="slug"
on the LocationFormparent
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)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 extendedprepare_cloned_fields
to look up the associated edit form, and in the case where a FK model field has a form field withto_field_name
defined, use that field from the related object instead of its PK.DynamicModelChoiceMixin.get_bound_field
because I tripped over aValidationError
when initially exploring this issue.get_related_class_for_model
to accept a model instance as a valid input.TODO
prepare_cloned_fields
; I'll see about adding some