Skip to content

Filtering by related model with custom related_query_name doesn't work #146

@kvbrg

Description

@kvbrg

Suppose we have two models: Patient and Slot.

class Slot(Model):
   ...
   email = EmailField(...)
   patient = models.ForeignKey(
       'patients.Patient',
       related_name='slots',
       related_query_name='slot',
       ...
    )

And then we need to filter patients by related slot.

def get_patients():
   ...
   # patients is queryset of patients.Patient
   return patients.filter(slot__email__isnull=True)

It's simple and working code. But when we try to mock get_patients with MockSet of patients created with fabric we get an error.

django.core.exceptions.FieldError: Cannot resolve keyword 'slot' into field. Choices are ...'slots', ...

If we change filter to slots__email__isnull=True, it works in tests. But now we get an error in Django shell.

django.core.exceptions.FieldError: Cannot resolve keyword 'slots' into field. Choices are: ... 'slot', ...

It would be great to fix this! Thanks. 😊

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions