ericls / django-hashids

Non-intrusive hashids library for Django
MIT License
42 stars 11 forks source link

Relationship lookup #29

Closed teotwaki closed 2 years ago

teotwaki commented 2 years ago

Hi,

Many thanks for this library. It is very useful and massively underrated.

I was wondering if I missed something in the documentation, but I couldn't get the following use-case to work: I would like to query an object based on a relationship. Like so:

class ModelA(models.Model):
    hashid = HashidsField()
    name = models.TextField()

class ModelB(models.Model):
    modela = models.ForeignKey(ModelA, on_delete=models.CASCADE)

results = ModelB.objects.filter(modela__hashid = "ZB07")

However, this doesn't appear to be working. Am I doing something wrong, or is this not supported?

Thanks in advance!

teotwaki commented 2 years ago

Nevermind, I'm an idiot, it was an issue on my side.

ericls commented 2 years ago

@teotwaki , glad the issue resolved itself. To make it more future proof, I added some test cases for related models

teotwaki commented 2 years ago

@ericls that was exactly the test I looked for, and when I couldn't find it, I assumed that maybe that use-case wasn't very common (I picked up Django the same day I created the issue).

Thanks for being a library owner!