Django-South 内省规则不起作用
我正在使用 Django 1.2.3 和 South 0.7.3。
我正在尝试将我的应用程序(名为 core
)转换为使用 Django-South。我正在使用一个自定义模型/字段,名为 ImageWithThumbsField
。它基本上只是 ol' django.db.models.ImageField ,具有一些属性,例如高度、重量等。
在尝试 ./manage.py Convert_to_auth core 时,我收到了南队的冻结错误。我不知道为什么,我可能错过了一些东西......
我正在使用一个简单的自定义模型:
from django.db.models import ImageField
class ImageWithThumbsField(ImageField):
def __init__(self, verbose_name=None, name=None, width_field=None, height_field=None, sizes=None, **kwargs):
self.verbose_name=verbose_name
self.name=name
self.width_field=width_field
self.height_field=height_field
self.sizes = sizes
super(ImageField, self).__init__(**kwargs)
是我的内省规则,我将其添加到我的 models.py
的顶部:
from south.modelsinspector import add_introspection_rules
from lib.thumbs import ImageWithThumbsField
add_introspection_rules(
[
(
(ImageWithThumbsField, ),
[],
{
"verbose_name": ["verbose_name", {"default": None}],
"name": ["name", {"default": None}],
"width_field": ["width_field", {"default": None}],
"height_field": ["height_field", {"default": None}],
"sizes": ["sizes", {"default": None}],
},
),
],
["^core/.fields/.ImageWithThumbsField",])
这 是我收到的错误:
! Cannot freeze field 'core.additionalmaterialphoto.photo'
! (this field has class lib.thumbs.ImageWithThumbsField)
! Cannot freeze field 'core.material.photo'
! (this field has class lib.thumbs.ImageWithThumbsField)
! Cannot freeze field 'core.material.formulaimage'
! (this field has class lib.thumbs.ImageWithThumbsField)
! 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
有人知道为什么吗?我做错了什么?
I'm using Django 1.2.3
and South 0.7.3
.
I am trying to convert my app (named core
) to use Django-South. I have a custom model/field that I'm using, named ImageWithThumbsField
. It's basically just the ol' django.db.models.ImageField
with some attributes such as height, weight, etc.
While trying to ./manage.py convert_to_auth core
I receieve South's freezing errors. I have no idea why, I'm Probably missing something...
I am using a simple custom Model:
from django.db.models import ImageField
class ImageWithThumbsField(ImageField):
def __init__(self, verbose_name=None, name=None, width_field=None, height_field=None, sizes=None, **kwargs):
self.verbose_name=verbose_name
self.name=name
self.width_field=width_field
self.height_field=height_field
self.sizes = sizes
super(ImageField, self).__init__(**kwargs)
And this is my introspection rule, which I add to the top of my models.py
:
from south.modelsinspector import add_introspection_rules
from lib.thumbs import ImageWithThumbsField
add_introspection_rules(
[
(
(ImageWithThumbsField, ),
[],
{
"verbose_name": ["verbose_name", {"default": None}],
"name": ["name", {"default": None}],
"width_field": ["width_field", {"default": None}],
"height_field": ["height_field", {"default": None}],
"sizes": ["sizes", {"default": None}],
},
),
],
["^core/.fields/.ImageWithThumbsField",])
This is the errors I receieve:
! Cannot freeze field 'core.additionalmaterialphoto.photo'
! (this field has class lib.thumbs.ImageWithThumbsField)
! Cannot freeze field 'core.material.photo'
! (this field has class lib.thumbs.ImageWithThumbsField)
! Cannot freeze field 'core.material.formulaimage'
! (this field has class lib.thumbs.ImageWithThumbsField)
! 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
Does anybody know why? What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我得到了它! :)
我改变了这个:
["^core/.fields/.ImageWithThumbsField",]
改为:
["^lib\.thumbs\.ImageWithThumbsField",]
这整行是Django字段类型的python路径的正则表达式(再读一遍,长句子)。
South 偶然发现了在路径
lib.thumbs
中声明的字段名称ImageWithThumbsField
。我给了他一条错误的道路,所以南在偶然发现这片土地时仍然不知道该怎么办。一旦我给了他正确的路径,它就知道在他到达后如何处理该字段。
I got it! :)
I changed this:
["^core/.fields/.ImageWithThumbsField",]
To this:
["^lib\.thumbs\.ImageWithThumbsField",]
This whole line is a regular-expression of python paths of Django field types (read this again, long sentence).
South stumbled upon a field name
ImageWithThumbsField
that was declared in the pathlib.thumbs
. I gave him a wrong path, so South still didn't know what to do when stumbling upon this field.Once I gave him the correct path, it knew how to handle the field once he got to it.