'Creating custom fields with django-filters

I have a model as shown below. The model has the attribute type as a foreign key.

class YachtGeneralInfo(models.Model):
    type = models.ForeignKey(
        YachtTypes,
        related_name="yachts_in_type",
        on_delete=models.PROTECT,
        blank=False,
        null=False,
    )
    ....
    ....

I wrote a view class like this -

class YachtGeneralInfoView(ListAPIView):

    pagination_class = PageNumberPagination
    serializer_class = YachtGeneralInfoSerializer
    filter_backends = [OrderingFilter, SearchFilter, DjangoFilterBackend]
    filterset_fields = [
        "status",
        "is_professional",
        "chartered_with__id",
        "harbour__id",
        "harbour__city__id",
        "model__id",
    ]
    search_fields = ["name", "company_name", "website", "owner__name"]

I would like to add another filter for field type. However, I want to provide multiple values for this query parameter like [1,2,3].

If I do that directly with queryset then it would be like this -

queryset = YachtGeneralInfo.objects.filter(type__in=[1,2,3])

Is there a way I could write a custom filter set field to accomplish this instead of having it directly in the queryset?



Solution 1:[1]

It turns that, quoting a member from the Function Programming Discord, "it's a known issue with haskeline (the library GHCi) uses that been fixed but needs to be back ported into GHC itself"

A workaround suggested by the same person is running TERM=dumb ghci

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 roger