Last active
February 7, 2019 20:33
-
-
Save maxpoletaev/60cc804a48fdf3eeb1c8ad54b80f3137 to your computer and use it in GitHub Desktop.
This file contains hidden or 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.db import connection | |
from django.utils.deconstruct import deconstructible | |
def nextval(regclass): | |
with connection.cursor() as cursor: | |
cursor.execute(f"select nextval('{regclass}')") | |
next_id_row = cursor.fetchone() | |
return next_id_row[0] | |
@deconstructible | |
class NextSeqValue: | |
def __init__(self, regclass): | |
self.regclass = regclass | |
def __call__(self): | |
return nextval(self.regclass) | |
def __eq__(self, other): | |
return self.regclass == other.regclass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment