Django:来自ManyToManyField的对象过滤

时间:2018-05-03 08:55:23

标签: python django

我有一个问题&答案模型,任何人都可以回答问题&也问一个问题。

import csv

example_list = [[1,2,3], [4,5,6], [7,8,9]]

with open('example.csv', 'w', newline='') as f:
    writer = csv.writer(f)
    writer.writerows(example_list)

如果# question model class Question(models.Model): text = models.TextField() followers = models.ManyToManyField(settings.AUTH_USER_MODEL, blank=True) # answer model class Answer(models.Model): text_answer = models.TextField() question = models.ForeignKey(Question, on_delete=models.CASCADE) 是关注者列表,我如何过滤Answer

我试过了request.user,但它没有用。

0 个答案:

没有答案