dabapps / django-readers

A lightweight function-oriented toolkit for better organisation of business logic and efficient selection and projection of data in Django projects.
https://www.django-readers.org
BSD 2-Clause "Simplified" License
183 stars 7 forks source link

Issue with using Proxy models #103

Open andrew-gibson opened 1 week ago

andrew-gibson commented 1 week ago

take the case of :

class CoreModel(models.Model):
   name = models.TextField()

class ProxyModel(CoreModel):
   class Meta:
        proxy = True

in qs.py, when resolving a where a model has a relationship with ProxyModel, the code currently traverses:: related_descriptor.rel.field.model however, if the related model is ProxyModel , then this resolution path ends up with CoreModel

If you instead follow: related_descriptor.rel.model._meta.proxy, you can check if it's a proxy model and then related_queryset = related_descriptor.rel.model.objects.all() will get you the right qs

j4mie commented 1 week ago

Hi @andrew-gibson, thank you for reporting this! I'll see if I can reproduce this with a test case when I get some time.

andrew-gibson commented 1 week ago

@j4mie thanks for the reply, i'm sure there was a move professional way of submitting this. Would you like me to submit a file which highlights where it falls down?

j4mie commented 1 week ago

No, that's absolutely fine - the example you gave should be plenty. Thanks again.