Skip to content

Instantly share code, notes, and snippets.

@safhac
Created September 5, 2021 09:02
Show Gist options
  • Save safhac/589ab918d5e6482937e00b74540ae424 to your computer and use it in GitHub Desktop.
Save safhac/589ab918d5e6482937e00b74540ae424 to your computer and use it in GitHub Desktop.
django model manager overrides
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