Created
December 31, 2021 15:20
-
-
Save thorin-schiffer/96227c1ad06f67c54251bc804ac635da to your computer and use it in GitHub Desktop.
Django-plpy custom ORM lookups
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django_plpy.installer import plfunction | |
from django.db.models import Transform | |
from django.db.models import IntegerField | |
from tests.books.models import Book | |
@plfunction | |
def plsquare(a: int) -> int: | |
return a * a | |
class PySquare(Transform): | |
lookup_name = "plsquare" | |
function = "plsquare" | |
IntegerField.register_lookup(PySquare) | |
assert Book.objects.filter(amount_stock__plsquare=400).exists() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment