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

Column with Foreignkey - limit_choices_to not working as intended #252

Open
kvdogan opened this issue May 13, 2021 · 0 comments
Open

Column with Foreignkey - limit_choices_to not working as intended #252

kvdogan opened this issue May 13, 2021 · 0 comments

Comments

@kvdogan
Copy link
Contributor

kvdogan commented May 13, 2021

I have a model field as follows;

class Tag(models.Model):
    TAG_USER_GROUP_NAME = "X_TEAM"

    def limit_user_selection_to_group_user(group_name):
        result = dict(groups__name=group_name, is_active=True)
        return result

    checked_by = models.ForeignKey(
        settings.AUTH_USER_MODEL,
        verbose_name="Checked",
        limit_choices_to=limit_user_selection_to_group_user(TAG_USER_GROUP_NAME),
        blank=True, null=True,
        related_name='tagtracking_tags_checked',
        on_delete=models.SET_NULL
    )

Datatable setup as follows:

class TagDatatable(Datatable):
    ...
    checked_by = columns.TextColumn(
        sources=['checked_by__username'], processor=helpers.make_xeditable
    )

Issue is datatable validates input according to the limit_choices_to function correctly but It does not limit choices according to the rule, it shows all the choices but allows only validated ones to save.

rh0dium pushed a commit that referenced this issue Nov 11, 2024
* Bootstrap structure has been improved

* Filter xeditable choices for Foreignkey field with limit_choices_to

* Add textarea to XEDITABLE_FIELD_TYPES

* Compatibility fix for >= Django 3.1 with regard to
ModelChoiceIteratorValue for choice fields with foreign key

---------

Co-authored-by: kvdogan <[email protected]>
Co-authored-by: kvdogan <[email protected]>
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

No branches or pull requests

1 participant