Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Proxy model returning parent model

I am having a strange issue here with django 1.6.5.

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?

like image 478
Titusz Avatar asked Jun 10 '26 10:06

Titusz


1 Answers

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

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
like image 158
Titusz Avatar answered Jun 12 '26 23:06

Titusz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!