Django代理模型返回父模型
16lz
2021-01-22
I am having a strange issue here with django 1.6.5.
我对django有个奇怪的问题。
In distribution.models I have:
from core.models import Book, Person
class Proxy1(Book):
class Meta:
proxy = True
class Proxy2(Person):
class Meta:
proxy = True
how can this happen?:
>>> from distribution.models import Proxy1, Proxy2
>>> type(Proxy1.objects.first())
<class 'core.models.Book'>
>>> type(Proxy2.objects.first())
<class 'distribution.models.Proxy2'>
Any ideas where to hunt for the cause?
有什么办法去寻找这个原因吗?
1 个解决方案
#1
1
After a lot of hours hunting I finally found the culprit. The MoneyField from the django-money package does some dark magic on the model manager that somehow breaks returning the correct model class for proxy models. I filed an issue: https://github.com/jakewins/django-money/issues/80
经过几个小时的搜捕,我终于找到了罪犯。来自django-money包的MoneyField对模型管理器做了一些黑暗的魔法,以某种方式破坏了为代理模型返回正确的模型类。我提交了一个问题:https://github.com/jakewins/django-money/issues/80
I settled with an easy workaround by manually overriding the 'objects' attribute on the proxy class like this:
通过手动覆盖代理类上的“对象”属性,我解决了一个简单的解决方案:
class ProxyModel(SomeModelWithMoneyField):
# This fixes django-money that would else return parent objects
objects = models.Manager()
class Meta:
proxy=True
更多相关文章
- 无法安装ndg-httpsclient或者我的解决方案错误
- [caffe(二)]Python加载训练caffe模型并进行测试2
- Linux无法连接网络解决方案
- 新人求助:tensorflow官方文档里构建第一个多层卷积网络,训练和评估
- Media-S 简介(一个开源的DRM解决方案)
- 双插槽与单插槽内存模型?
- 如何使用来自其他模型的信息来注释查询集,或者在Django Rest Fram
- AppScan安全问题解决方案
- PLSQL乱码解决方案