pivotal-energy-solutions / django-datatable-view

Server-side datatable representations for Django querysets for automatic rendering in templates
Apache License 2.0
347 stars 141 forks source link

Column with Foreignkey - limit_choices_to not working as intended #252

Open kvdogan opened 3 years ago

kvdogan commented 3 years ago

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.