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

更多相关文章

  1. 无法安装ndg-httpsclient或者我的解决方案错误
  2. [caffe(二)]Python加载训练caffe模型并进行测试2
  3. Linux无法连接网络解决方案
  4. 新人求助:tensorflow官方文档里构建第一个多层卷积网络,训练和评估
  5. Media-S 简介(一个开源的DRM解决方案)
  6. 双插槽与单插槽内存模型?
  7. 如何使用来自其他模型的信息来注释查询集,或者在Django Rest Fram
  8. AppScan安全问题解决方案
  9. PLSQL乱码解决方案

随机推荐

  1. [ZZ]Android UI Automated Testing
  2. Android初小试---一分钟傻瓜式打包
  3. android studio 提示no android sdk foun
  4. Robotium Recorder的初试
  5. Android各种花式酷炫自定义控件开源库集
  6. 关于RelativeLayout的一点经验
  7. android 4.0 sdk直接下载地址
  8. UI
  9. andoid sys bug 转载
  10. [Android] Android的音频采集