【问题标题】:Adding custom field and updating model problem in django在 django 中添加自定义字段和更新模型问题
【发布时间】: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


【解决方案1】:

数据库中的字段名为colorfield,但模型中的字段名为color。您必须更改其中一项才能使其再次工作。

【讨论】:

    猜你喜欢
    • 2016-02-01
    • 1970-01-01
    • 2021-12-09
    • 2019-01-28
    • 2020-01-10
    • 1970-01-01
    • 2020-04-20
    • 2014-04-02
    • 2013-07-15
    相关资源
    最近更新 更多