Skip to content

Commit

Permalink
Fix: use local_concrete_fields
Browse files Browse the repository at this point in the history
  • Loading branch information
hvdklauw authored and bmispelon committed May 21, 2024
1 parent ced3d05 commit 39394a5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
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() if f.concrete}
declared = {f.column for f in model._meta.local_concrete_fields}
if fields is None:
return declared

Expand Down
15 changes: 14 additions & 1 deletion testproject/testapp/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,21 @@
import time_machine
from django.test import TestCase
from model_bakery import baker
from modelsubquery.functions import _model_fields

from .models import Book, Person
from .models import Book, Person, Shelve


class ModelFieldTest(TestCase):
def test_model_fields_book(self):
fields = _model_fields(Book, None)
self.assertEqual(
fields, {"id", "title", "author_id", "published", "rating", "has_cover"}
)

def test_model_fields_shelve(self):
fields = _model_fields(Shelve, None)
self.assertEqual(fields, {"id", "title"})


@time_machine.travel("2000-01-01")
Expand Down

0 comments on commit 39394a5

Please sign in to comment.