Skip to content

Instantly share code, notes, and snippets.

@maxpoletaev
Last active February 7, 2019 20:33
Show Gist options
  • Save maxpoletaev/60cc804a48fdf3eeb1c8ad54b80f3137 to your computer and use it in GitHub Desktop.
Save maxpoletaev/60cc804a48fdf3eeb1c8ad54b80f3137 to your computer and use it in GitHub Desktop.
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