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

Simplify MultipleContentTypeField boilerplate #98

Closed
glennmatthews opened this issue Mar 5, 2021 · 1 comment · Fixed by #179
Closed

Simplify MultipleContentTypeField boilerplate #98

glennmatthews opened this issue Mar 5, 2021 · 1 comment · Fixed by #179
Assignees
Labels
good first issue Great issues for newcomers! type: housekeeping Changes to the application which do not directly impact the end user
Milestone

Comments

@glennmatthews
Copy link
Contributor

glennmatthews commented Mar 5, 2021

Proposed Changes

Followup to #92 - Provide a custom __init__ method for the MultipleContentTypeField class, so that we can more simply instantiate it, along the lines of:

source_type = MultipleContentTypeField(feature="relationships", required=False, label="Source Type")

Possibly something similar should also be implemented for CSVMultipleContentTypeField?

Justification

Currently there's a lot of boilerplate in instantiating a MultipleContentTypeField, particularly in constructing and ordering the queryset correctly.

    source_type = MultipleContentTypeField(
        queryset=ContentType.objects.filter(FeatureQuery("relationships").get_query()).order_by("app_label", "model"),
        required=False,
        label="Source Type",
        widget=StaticSelect2Multiple(),
    )

    destination_type = MultipleContentTypeField(
        queryset=ContentType.objects.filter(FeatureQuery("relationships").get_query()).order_by("app_label", "model"),
        required=False,
        label="Destination Type",
        widget=StaticSelect2Multiple(),
    )

It would be nice if we could instantiate it with a simple feature="relationships" and have the appropriate queryset get automatically constructed and ordered. It also probably makes sense for this field to default to using a StaticSelect2Multiple widget instead of requiring that to be manually specified each time.

@glennmatthews glennmatthews added good first issue Great issues for newcomers! status: current type: housekeeping Changes to the application which do not directly impact the end user labels Mar 5, 2021
@glennmatthews glennmatthews added this to the v1.0.0 milestone Mar 5, 2021
@jedelman8
Copy link
Contributor

@glennmatthews can you take this for 1.0.0 ?

@glennmatthews glennmatthews self-assigned this Mar 22, 2021
@jathanism jathanism added this to In progress in Release v1.0.0 Mar 24, 2021
Release v1.0.0 automation moved this from In progress to Done Mar 26, 2021
glennmatthews added a commit that referenced this issue Mar 26, 2021
* Improve usability of MultipleContentTypeField. Fixes #98.

* Fix issues reported in code review

* Update nautobot/extras/forms.py

* Update nautobot/extras/forms.py

* Update nautobot/extras/forms.py

Co-authored-by: Jathan McCollum <jathan@gmail.com>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Great issues for newcomers! type: housekeeping Changes to the application which do not directly impact the end user
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

2 participants