Created
September 5, 2021 09:02
-
-
Save safhac/589ab918d5e6482937e00b74540ae424 to your computer and use it in GitHub Desktop.
django model manager overrides
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
class MyClassQuerySet(models.query.QuerySet): | |
def get(self, **kwargs): | |
print('hello world') | |
try: | |
return super().get(**kwargs) | |
except: | |
return None | |
class MyClassManager(models.Manager.from_queryset(MyClassQuerySet)): | |
pass | |
# Create your models here. | |
class MyClass(models.Model): | |
objects = MyClassManager() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment