Skip to content

Commit

Permalink
Fix: ManyToOne and ManyToMany relations.
Browse files Browse the repository at this point in the history
Only concrete fields should be used.
  • Loading branch information
hvdklauw authored and bmispelon committed May 21, 2024
1 parent 49d50c7 commit ced3d05
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/modelsubquery/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions testproject/testapp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

0 comments on commit ced3d05

Please sign in to comment.