在 django 中使用 uuid 作为 id/pk 会破坏管理页面
我正在使用 django 1.0.4 并且有 3 个模型:类别 <-1-m->项目<-1-m->图像。
我最近将 id/pk 更改为 uuid:
id = models.CharField(max_length=32, primary_key=True,
default=make_uuid, editable=False)
...
def make_uuid():
return str(uuid.uuid4()).replace('-','')
在我开始使用 uuid 后,该项目的管理页面将不再允许我内联添加图像。即使没有任何错误,它也会给我一个表单验证错误。此外,如果一个项目有图像,我无法更改类别,它会给我以下错误:
KeyError at /admin/inventory/item/90965921681b4b69880b36bd716b0831/
id
...
/local/env/bfi2/lib/python2.6/site-packages/Django-1.0.4-py2.6.egg/django/forms/forms.py in _raw_value
213. field = self.fields[fieldname]
我认为这类似于以下错误: http://code.djangoproject.com/ticket/10992。理想情况下,我想避免升级 django 并只修补必要的文件。还有其他人遇到这个问题吗?
谢谢, 史蒂夫
i am using django 1.0.4 and have 3 models: Category <-1-m-> Item <-1-m-> Image.
i recently changed the id/pk to uuid:
id = models.CharField(max_length=32, primary_key=True,
default=make_uuid, editable=False)
...
def make_uuid():
return str(uuid.uuid4()).replace('-','')
after i started using uuid, the Item's admin page would no longer let me inline add an Image. it would give me a form validation error even though there isn't any error. furthemore, if an Item has an Image, i can't change the Category, it would give me the following error:
KeyError at /admin/inventory/item/90965921681b4b69880b36bd716b0831/
id
...
/local/env/bfi2/lib/python2.6/site-packages/Django-1.0.4-py2.6.egg/django/forms/forms.py in _raw_value
213. field = self.fields[fieldname]
i think this is similar to the following bug: http://code.djangoproject.com/ticket/10992. ideally, i would like to avoid upgrading django and just patch the necessary files. has anyone else ran into this problem?
thanks,
steve
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到过这样的问题,但它们通过 django-extensions UUID 字段解决了。< br>
但我不能保证这个 Field 可以与旧的 django 版本一起使用,它是 1.2.3
I've gone into such problems but they got solved with django-extensions UUID field.
But I cannot guarantee that this Field will work with an old django version, it was on 1.2.3