从 ManyToMany 添加 admin.py 中的字段
add fields in admin.py from a ManyToMany
我想为每个与其对应的问题页面显示我的 class 页面中有 4 个项目 ("visit 1 visit 2 visit 3 visit 4")
现在我似乎一次获得了所有页面...我想如果例如问题 "How old are you?" 是用访问 1 定义的,那么在管理面板 "Visite 1" 中
My models.py :
class Page(models.Model):
title = models.CharField(max_length=30)
def __str__(self):
return self.title
class Question(models.Model):
label = models.CharField(max_length=30)
page = models.ManyToManyField(Page)
def __str__(self):
return self.label
class Reply(models.Model):
question = models.ForeignKey(Question)
user = models.ForeignKey(Personne)
answer = models.CharField(max_length=30)
creationDate = models.DateTimeField(default=datetime.datetime(2016, 1, 20, 15, 4, 21, 467165))
def __str__(self):
return str(self.answer)
My admin.py :
class ReplyAdmin(admin.ModelAdmin):
list_display = ["__str__", "user", "question", "creationDate", "get_pages",]
def get_pages(self, objects):
return "\n".join([page.title for page in Page.objects.all()])
class Meta:
model = Reply
admin.site.register(Reply, ReplyAdmin)
为每个关联页面获取正确的行我必须面对的循环是什么
class ReplyAdmin(admin.ModelAdmin):
list_display = ["__str__", "user", "question", "creationDate", "get_pages",]
def get_pages(self, obj):
return "\n".join([page.title for page in obj.question.page.all()])
class Meta:
model = Reply
admin.site.register(Reply, ReplyAdmin)
我想为每个与其对应的问题页面显示我的 class 页面中有 4 个项目 ("visit 1 visit 2 visit 3 visit 4")
现在我似乎一次获得了所有页面...我想如果例如问题 "How old are you?" 是用访问 1 定义的,那么在管理面板 "Visite 1" 中
My models.py :
class Page(models.Model):
title = models.CharField(max_length=30)
def __str__(self):
return self.title
class Question(models.Model):
label = models.CharField(max_length=30)
page = models.ManyToManyField(Page)
def __str__(self):
return self.label
class Reply(models.Model):
question = models.ForeignKey(Question)
user = models.ForeignKey(Personne)
answer = models.CharField(max_length=30)
creationDate = models.DateTimeField(default=datetime.datetime(2016, 1, 20, 15, 4, 21, 467165))
def __str__(self):
return str(self.answer)
My admin.py :
class ReplyAdmin(admin.ModelAdmin):
list_display = ["__str__", "user", "question", "creationDate", "get_pages",]
def get_pages(self, objects):
return "\n".join([page.title for page in Page.objects.all()])
class Meta:
model = Reply
admin.site.register(Reply, ReplyAdmin)
为每个关联页面获取正确的行我必须面对的循环是什么
class ReplyAdmin(admin.ModelAdmin):
list_display = ["__str__", "user", "question", "creationDate", "get_pages",]
def get_pages(self, obj):
return "\n".join([page.title for page in obj.question.page.all()])
class Meta:
model = Reply
admin.site.register(Reply, ReplyAdmin)