Skip to content

Column with Foreignkey - limit_choices_to not working as intended  #252

@kvdogan

Description

@kvdogan

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.

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