Guest User

Untitled

a guest
Mar 24th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. class SerialField(models.Field):
  2. description = _("BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE")
  3.  
  4. empty_strings_allowed = False
  5.  
  6. default_error_messages = {
  7. 'invalid': _("'%(value)s' value must be an integer."),
  8. }
  9.  
  10. def __init__(self, *args, **kwargs):
  11. kwargs['blank'] = True
  12. super().__init__(*args, **kwargs)
  13.  
  14. def db_type(self, connection):
  15. return 'serial'
  16.  
  17. from .fields import SerialField
  18.  
  19. class MyModel(models.Model):
  20. uuid = models.UUIDField(
  21. verbose_name=_("UUID Identifier"),
  22. primary_key=True,
  23. default=uuid.uuid4,
  24. editable=False,
  25. help_text=_("Requried, PrimaryKey none-editable"),
  26. db_index=True,
  27. )
  28. number = SerialField(
  29. primary_key=False,
  30. editable=False,
  31. help_text=_("Auto Increment Number"),
  32. verbose_name=_("Number"),
  33. #null=True
  34. )
  35.  
  36. def forwards(apps, schema_editor):
  37. if schema_editor.connection.alias == 'default':
  38. return migrations.RunSQL(
  39. "ALTER SEQUENCE app_name_mymodel_number_seq RESTART WITH 100000"
  40. )
  41.  
  42.  
  43. class Migration(migrations.Migration):
  44.  
  45. dependencies = [
  46. ('activities', '0001_initial'),
  47. ]
  48.  
  49. operations = [
  50. migrations.RunPython(forwards)
  51. ]
Add Comment
Please, Sign In to add comment