在我的Django模型中,我按照本教程Django admin Google Maps创建了一个名为LocationField的自定义字段。
现在我的问题是使用南方的迁移似乎无法正常工作。它给了我一个错误
! Cannot freeze field 'SilverInningsHelpline.classified.location'
! (this field has class SilverInningsHelpline.widgets.LocationField)
! South cannot introspect some fields; this is probably because they are custom
! fields. If they worked in 0.6 or below, this is because we have removed the
! models parser (it often broke things).
! To fix this, read http://south.aeracode.org/wiki/MyFieldsDontWork
为了解决这个问题,我添加了南方文档中定义的检查规则,如下所示:
from south.modelsinspector import add_introspection_rules
add_introspection_rules([
(
[Classified],
[],
{
"location": ["LocationField", {"blank": "true"}]
}
)
], ["^southut\.fields\.Classified"])
其中分类模型包含LocationField。我的分类模型如下:
class Classified(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(max_length=256)
contact_person = models.CharField(max_length=300)
email = models.CharField(max_length=100)
address = models.ForeignKey(Address)
subcategory = models.ForeignKey(Subcategory)
phone_number = models.BigIntegerField(max_length=20, default=0)
secondary_number = models.BigIntegerField(max_length=20, default=0, blank=True)
more_numbers = models.CharField(max_length=300, default='', blank=True)
image = S3DirectField(upload_to='s3direct', blank=True)
description = models.TextField(max_length=1000, blank=True)
location = LocationField(blank=True, max_length=255)
任何解决此问题的建议都将受到大力赞赏。
答案 0 :(得分:0)
看起来你似乎没有费心阅读文档。
您正在传递模型类(Classified
),其中add_instrospection_rules
期望您的字段类(LocationField
)。
'keyword arguments'dict应该描述你的字段所期望的关键字args,而不是描述你的字段在给定模型类中的使用方式
末尾的限定字段名称模式应与您的字段的限定名称相匹配,而不是教程中的内容和模型类名称的随机mumbo jumbo组合。