【发布时间】:2010-12-10 13:24:32
【问题描述】:
我需要在我的 django 模型中添加一个颜色选择器并编写一个自定义小部件。但是,当我将此 colordfield 添加到我的模型时,django 会出现此错误:
column mediaplanner_ievent.color does not exist
LINE 1: ...nt"."bits", "mediaplanner_ievent"."capture_link", "mediaplan...
我的模型是:
from mediaplanner.custom_widgets import ColorPickerWidget
class ColorField(models.CharField):
def __init__(self,*args, **kwargs):
kwargs['max_length'] = 10
super(ColorField, self).__init__(*args, **kwargs)
def formfield(self, **kwargs):
kwargs['widget'] = ColorPickerWidget
return super(ColorField, self).formfield(**kwargs)
class iEvent(models.Model):
name = models.CharField(verbose_name= u"Uygulama Adı", max_length=100, unique=True)
bits = models.CommaSeparatedIntegerField(verbose_name= u"Bitler",max_length=100)
capture_link = models.URLField(verbose_name= u"Capture URL", null=True, blank=True)
color = ColorField(blank=true)
class Meta:
verbose_name = u"red button"
verbose_name_plural = u"red buttonlar"
def __unicode__(self):
return smart_str( "%s"% self.name )
奇怪的是,当我查看我的数据库时,存在色域。我不想删除数据库并再次加载它。但是当然,如果这是唯一的解决方案,那么别无选择..
那么有人可以帮我解决一下吗?
【问题讨论】:
-
您的问题对我来说似乎很不清楚,您没有在模型定义中使用
colorfield!此外,您的数据库中缺少color字段,而不是colorfield;您可能在创建表后添加了此字段...另外,请根据 django 指南命名您的类! -
抱歉,我更新了信息
标签: django customization models