Skip to content

ForeignKey access attribute. #158

@lvrfrc87

Description

@lvrfrc87

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'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions