Skip to content

Can we allow the smart select at the frontend, but just store only the ForeignKey to the "smart selected" dropdown? #363

@KommuSoft

Description

@KommuSoft

Something I think is missing in the package is to present the chained foreignkey in the (Model)Form, but not storing both ForeignKeys in the model, so it would be nice if we somehow can work with the smart select at the frontend, but at the same time store only the chained ForeignKey, so:

class Location(models.Model):
    country = ForeignKey(
        Country,
        chained_field="continent",
        chained_model_field="continent",
        show_all=False,
        auto_choose=True,
        sort=True)

and in the ModelForm with:

class ChainForm(forms.Form):
    continent = forms.ModelChoiceField(queryset=Continent.objects.all())
    country = ChainedModelChoiceField(queryset=Country.objects.all(), chained_field='continent', chained_model_field='continent', show_all=False, auto_choose=False, sort=True, to_app_name='my_app', to_model_name='Country', foreign_key_app_name='my_app', foreign_key_model_name='Continent', foreign_key_field_name='continent')

or something similar.

If I try this, it does not work, and for good reasons: it checks if there is a ChainedForeignKey, and that is not the case, so it is a security mechanism.

I'm wondering however if we can add some sort of exception to the security to allow both?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions