python 新手,一个简单的筛选把我搞懵逼了。 第一个 model: electrode
from django.db import models
# Create your models here.
class Electrode(models.Model):
name = models.CharField(max_length=32, null=True)
第二个 model: electrode_log
from django.db import models
from Application.views.electrode.models import Electrode
# Create your models here.
class ElectrodeLog(models.Model):
electrode = models.ForeignKey(Electrode, on_delete=models.CASCADE, default=None, null=True)
用的视图集 ModelViewSet ,求教怎么在筛选到 Electrode 表的 name ,万分感激。
1
gotounix 2022-08-08 20:48:08 +08:00
from django_filters import rest_framework as filters
from rest_framework import viewsets class ElectrodeLogFilter(filters.FilterSet): ....electrode__name = filters.CharFilter(lookup_expr='icontains') class ElectrodeLogViewSet(viewsets.ModelViewSet): ....filterset_class = ElectrodeLogFilter ....为空格 |