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

Different results when order is changed. #72

Open
instasck opened this issue May 2, 2021 · 0 comments
Open

Different results when order is changed. #72

instasck opened this issue May 2, 2021 · 0 comments

Comments

@instasck
Copy link

instasck commented May 2, 2021

I get wired behaver:
image

While changing the order of AND conditions:
image

I get this user appear.
While user have both many_to_many "he" and "ar"
image

This is the code I changed:

class FollowerLangField(StrField):
    name = 'language'
    model = Follower

    # def get_lookup_name(self):
    #     print(f'language__id')
    #     return 'language__id'

    # def get_lookup_value(self, value):
    #     lang_id = Language.objects.filter(code_name=value).first().id
    #     print(f'lang_id {lang_id}')
    #     return lang_id

    def get_lookup(self, path, operator, value):
        _search = 'language__id' #'__'.join(path + [self.get_lookup_name()])
        _op, invert = self.get_operator(operator)
        _value = Language.objects.filter(code_name=value).first().id
        print('debug get_lookup:',_search, _op, invert, _value)
        if operator == '!=':
            q = models.Q(**{'%s%s' % (_search, _op): _value})
        else:
            q = models.Q(**{'%s%s' % (_search, _op): _value})
        return ~q if invert else q


...
model:
class Follower(models.Model):
    language = models.ManyToManyField(
            "instagram_data.Language", verbose_name=_("language_code_name"), blank=True)


class Language(models.Model):
    code_name = models.CharField(max_length=6, null=True, blank=True)

    def __str__(self):
        return self.code_name

It seems to ignore the second "language" condition.

Y?

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