Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django rest框架根据与外键连接的其他模型的名称筛选模型_Python_Django_Django Rest Framework - Fatal编程技术网

Python Django rest框架根据与外键连接的其他模型的名称筛选模型

Python Django rest框架根据与外键连接的其他模型的名称筛选模型,python,django,django-rest-framework,Python,Django,Django Rest Framework,每个博客文本都有其类型 现在我可以通过contains class Genre(models.Model): name = models.CharField(unique=True,max_length=255) def __str__(self): return self.name class BlogText(models.Model): mytext = models.TextField(null=True) genre = models.F

每个博客文本都有其类型

现在我可以通过
contains

class Genre(models.Model):
    name = models.CharField(unique=True,max_length=255)
    def __str__(self):
        return self.name
class BlogText(models.Model):
    mytext = models.TextField(null=True)
    genre = models.ForeignKey(Genre, on_delete=models.CASCADE,null=True,blank=True)
    pub_date = models.DateTimeField('date published')
然后我想通过
BlogText.genre.name

我在谷歌上搜索了一下,但没有找到除CharFilter包含的引用以外的其他引用。(甚至找不到IntFilter…我尝试直接筛选流派id…)

我该怎么做???

指定

genre=filters.CharFilter(查找\u expr='contains',字段\u name='genre\u name')
指定


genre=filters.CharFilter(lookup\u expr='contains',field\u name='genre\uu name')
非常感谢这对我来说非常简单明了。非常感谢这对我来说非常简单明了。
mytext = filters.CharFilter(lookup_expr='contains')
genre = filters.CharFilter(lookup_expr='contains', field_name='genre__name')