要解決Taggit問題,我試圖在標記字段中的值被引入到模型中之前添加引號。這是我迄今爲止的,但它不起作用。我究竟做錯了什麼?Django:在提交字段值之前修改字段值
class TagField(models.CharField):
description = "Simplifies entering tags w/ taggit"
def __init__(self, *args, **kwargs):
super(TagField, self).__init__(self, *args, **kwargs)
# Adds quotes to the value if there are no commas
def to_python(self, value):
if ',' in value:
return value
else:
return '"' + value + '"'
class CaseForm(forms.ModelForm):
class Meta:
model = Case
fields = ['title', 'file', 'tags']
labels = {
'file': 'Link to File',
'tags': 'Categories'
}
widgets = {
'tags': TagField()
}
我的回答是否有效? – metahamza