django-datatable-view icon indicating copy to clipboard operation
django-datatable-view copied to clipboard

Column with Foreignkey - limit_choices_to not working as intended

Open kvdogan opened this issue 3 years ago • 0 comments

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.

kvdogan avatar May 13 '21 20:05 kvdogan