我的模型 IPInfo 中有以下选择字段class IPInfoModel(models.Model): TYPE_INTRANET = 1 TYPE_INTERNET = 2 IP_TYPES = ( (TYPE_INTRANET, u'INTRANET'), (TYPE_INTERNET, u'INTERNET'), ) ip = models.GenericIPAddressField("IP", unique=True) ip_type = models.SmallIntegerField(choices=IP_TYPES)我使用 django_filters 来过滤 IPInfo。from django_filters import rest_framework as django_filters class IPInfoFilter(django_filters.FilterSet): ip_type = django_filters.ChoiceFilter(choices=IPInfoModel.IP_TYPES) class Meta: model = IPInfoModel fields = ["ip_type",]class IPInfoViewSet(mixins.ListModelMixin, viewsets.GenericViewSet): queryset = IPInfoModel.objects.all() serializer_class = IPInfoSerializer filter_class = IPInfoFilter我想在 ip_type 上过滤 IPInfo。如何通过“内部网”或“互联网”过滤 IPInfo。不要使用“1”或“2”。
添加回答
举报
0/150
提交
取消