django-mock-queries icon indicating copy to clipboard operation
django-mock-queries copied to clipboard

ForeignKey access attribute.

Open lvrfrc87 opened this issue 3 years ago • 1 comments

Hi, First of all, thanks for sharing this! Is simply amazing to be able to mock QuerySet in few simple lines!

Saying that, I am trying to replicate a ForeignKey relation and access to its attribute. I understand it might not be supported by the library but do you have any suggestion to replicate such behavior?

Thanks a lot

from django_mock_queries.query import MockSet, MockModel


OPERATOR = MockSet(
    MockModel(
        name="Name_1",
        surname="Surname_1"
    )
)

TICKETS = MockSet(
    MockModel(
        change_id=123456,
        change_type="test",
        status="implementation",
        operator=OPERATOR,
        date_diff=-10
        ),
)

for x in TICKETS.all():
    op = x.operator_set.all()
    print(op)

The above returns:

AttributeError: 'NoneType' object has no attribute 'all'

lvrfrc87 avatar Oct 23 '22 18:10 lvrfrc87

Have you tried using django_mock_queries.mocks.mocked_relations?

stefan6419846 avatar May 10 '23 11:05 stefan6419846