8000 get_lookup_name doesn't work for the RelativeFIeld · Issue #124 · ivelum/djangoql · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

get_lookup_name doesn't work for the RelativeFIeld #124

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

Open
e-stepanov opened this issue Mar 25, 2025 · 0 comments
Open

get_lookup_name doesn't work for the RelativeFIeld #124

e-stepanov opened this issue Mar 25, 2025 · 0 comments

Comments

@e-stepanov
Copy link

Hi! Big thanks for your really useful package.

I have faced a problem with a RelativeField. According to docs it is possible to create custom RelativeField in order to create an alias for search fields. The simplest example is the following (not tested, just example):

from djangoql.schema import RelationField, DjangoQLSchema

class CustomField(RelationField):
    name = "group_alias"

    def get_lookup_name(self):
        return "group"

class UserQLSchema(DjangoQLSchema):
    def get_fields(self, model):
        fields = super().get_fields(model)
        if model == User:
            fields += [CustomField(User, "group_alias", Group)]
        return fields


class UserQLQuerySet(DjangoQLQuerySet):
    djangoql_schema = UserQLSchema

class Group(models.Model):
    name = models.CharField()

class User(models.Model):
    group = models.ForeignKey(Group, on_delete=models.CASCADE)

The following exception is raised when I search by group_alias:

django.core.exceptions.FieldError: Cannot resolve keyword 'group_alias' into field. Choices are: list of User fields is here

After a bit of research I have realized that get_lookup_name isn't called for RelationField during name resolving. In other words we should replace item from the name.parts array with custom lookup name. If this is true I'm ready to create PR.

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

1 participant
0