parent
f9c2b72a6d
commit
554c1b8c6c
12 changed files with 117 additions and 26 deletions
@ -0,0 +1,22 @@ |
||||
from django.contrib.contenttypes.models import ContentType |
||||
from django.core.management.base import BaseCommand, CommandError |
||||
from django.db import connection |
||||
from lms.settings import apps |
||||
|
||||
|
||||
class Command(BaseCommand): |
||||
help = 'Set seq by last id in table.' |
||||
|
||||
def handle(self, **_): |
||||
with connection.cursor() as cursor: |
||||
for i in ContentType.objects.all(): |
||||
if i.app_label in apps: |
||||
model_name = "%s_%s" % (i.app_label, i.model) |
||||
cursor.execute('BEGIN') |
||||
cursor.execute('LOCK TABLE %s IN EXCLUSIVE MODE' % model_name) |
||||
cursor.execute( |
||||
"""SELECT setval('%s_id_seq', COALESCE( |
||||
(SELECT MAX(id)+1 FROM %s), 1) ,false |
||||
)""" % (model_name, model_name) |
||||
) |
||||
cursor.execute('COMMIT') |
||||
@ -0,0 +1,10 @@ |
||||
from rest_framework import serializers |
||||
|
||||
from storage.models import Storage |
||||
|
||||
|
||||
class StorageSerializer(serializers.ModelSerializer): |
||||
|
||||
class Meta: |
||||
model = Storage |
||||
exclude = ('id',) |
||||
Loading…
Reference in new issue