Python Django的South未冻结自定义字段
在我的Django模型中,我根据本教程创建了一个名为LocationField的自定义字段 现在我的问题是,使用南方移民似乎不起作用。它给了我一个错误Python Django的South未冻结自定义字段,python,django,django-south,Python,Django,Django South,在我的Django模型中,我根据本教程创建了一个名为LocationField的自定义字段 现在我的问题是,使用南方移民似乎不起作用。它给了我一个错误 ! Cannot freeze field 'SilverInningsHelpline.classified.location' ! (this field has class SilverInningsHelpline.widgets.LocationField) ! South cannot introspect some fields;
! 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
为了解决这个问题,我添加了由South文档定义的检查规则,如下所示:
from south.modelsinspector import add_introspection_rules
add_introspection_rules([
(
[Classified],
[],
{
"location": ["LocationField", {"blank": "true"}]
}
)
], ["^southut\.fields\.Classified"])
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)
其中分类模型包含LocationField。我的分类模型如下:
from south.modelsinspector import add_introspection_rules
add_introspection_rules([
(
[Classified],
[],
{
"location": ["LocationField", {"blank": "true"}]
}
)
], ["^southut\.fields\.Classified"])
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)
任何解决这一问题的建议都将不胜感激 看来你根本没看医生
Classified
),其中add\u instrspection\u rules
需要您的字段类(LocationField
)谢谢你的粗鲁解释。你的解决方案无论如何都不管用。无论如何,谢谢。@Newtt:谢谢你的粗鲁评论。我利用业余时间阅读了你的帖子,阅读了文档,并给出了一个答案,指出了你代码中至少三个明显的错误,我认为这就是“修复此问题的建议”。如果您试图修复代码,但又出现了另一个错误,请更新您的帖子。哦,是的,在陈述显而易见的事情时没有什么不礼貌的地方,
add\u introspection\u rules
所期望的是有文档记录的,而且我从来没有遇到过在文档之后向南方添加inspection rules的问题。