值我有以下型号Django表单排除choicefield
class ActionConfirm(models.Model):
CONFIRM_METHOD = (
(u'ce', u'Certificate'),
(u'tf', u'Trainee Feedback'),
(u'ms', u'Multi Source Feedback'),
(u'rp', u'Reflection upon Practice'),
(u'ot', u'Other - Please add/describe')
)
confirm_method = models.CharField(max_length=2, choices=CONFIRM_METHOD)
user = User
和下面的表格
class ActionConfirmForm(forms.ModelForm):
class Meta:
model = ActionConfirm
,我知道我可以做
selected = ActionConfirm.objects.filter(user=user)
得到他们目前的选择
那么如何从他们已经选择的confirm_method字段中排除值呢?
如果它是从一个数据库我知道我可以做choices = ActionConfirm.objects.exclude(choice__in = selected)
但我不知道如何做它时,它是从元组元组。
只是为了澄清 - 你试图使它所以用户只能创建'ActionConfirm'实例与'confirm_method'值*它们*没有用于以前创建的'ActionConfirm'实例? – 2010-09-08 08:39:25
是的,这是正确的。我没有把上面的ActionConfirm模型中的所有字段。还有一个用户字段,并且selected =应该是ActionConfirm.objects.filter(user = user)而不是ConfirmChoices。现在应该更新 – John 2010-09-08 08:44:44