From ced3d054b3adbdc2b955c9672dcc05b911e88816 Mon Sep 17 00:00:00 2001 From: Harro van der Klauw Date: Tue, 14 May 2024 12:02:36 +0200 Subject: [PATCH] Fix: ManyToOne and ManyToMany relations. Only concrete fields should be used. --- src/modelsubquery/functions.py | 2 +- testproject/testapp/models.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/modelsubquery/functions.py b/src/modelsubquery/functions.py index 1c8dbde..9051d13 100644 --- a/src/modelsubquery/functions.py +++ b/src/modelsubquery/functions.py @@ -13,7 +13,7 @@ def _model_fields(model, fields): then return all the declared fields. """ # TODO: the pk/id field should always be returned - declared = {f.column for f in model._meta.get_fields()} + declared = {f.column for f in model._meta.get_fields() if f.concrete} if fields is None: return declared diff --git a/testproject/testapp/models.py b/testproject/testapp/models.py index 0760033..6e29f72 100644 --- a/testproject/testapp/models.py +++ b/testproject/testapp/models.py @@ -31,3 +31,8 @@ class Person(models.Model): birth = models.DateField(default=date.today) objects = PersonQuerySet.as_manager() + + +class Shelve(models.Model): + title = models.CharField(max_length=100) + books = models.ManyToManyField("Book", related_name="shelves")