Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ForeignKey access attribute. #158

Open
lvrfrc87 opened this issue Oct 23, 2022 · 1 comment
Open

ForeignKey access attribute. #158

lvrfrc87 opened this issue Oct 23, 2022 · 1 comment

Comments

@lvrfrc87
Copy link

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'

@stefan6419846
Copy link
Collaborator

Have you tried using django_mock_queries.mocks.mocked_relations?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants