我有以下模型:
class Article(models.Model):
title = models.CharField()
description = models.TextField()
author = models.ForeignKey(User)
class Rating(models.Model):
value = models.IntegerField(choices=RATING_CHOICES)
additional_note = models.TextField(null=True, blank=True)
from_user = models.ForeignKey(User, related_name='from_user')
to_user = models.ForeignKey(User, related_name='to_user')
rated_article = models.ForeignKey(Article, null=True, blank=True)
dtobject = models.DateTimeField(auto_now_add=True)
基于上述模型,我创建了一个模型表单,如下:
模型形式:
class RatingForm(ModelForm):
class Meta:
model = Rating
exclude = ('from_user', 'dtobject')
不包括from_user
,因为request.user
是from_user
.
表单呈现良好,但在to_user
下拉字段中,作者也可以评价自己。所以我希望 current_user 的名称填充在下拉字段中。我该怎么做?