Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class SerialField(models.Field):
- description = _("BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE")
- empty_strings_allowed = False
- default_error_messages = {
- 'invalid': _("'%(value)s' value must be an integer."),
- }
- def __init__(self, *args, **kwargs):
- kwargs['blank'] = True
- super().__init__(*args, **kwargs)
- def db_type(self, connection):
- return 'serial'
- from .fields import SerialField
- class MyModel(models.Model):
- uuid = models.UUIDField(
- verbose_name=_("UUID Identifier"),
- primary_key=True,
- default=uuid.uuid4,
- editable=False,
- help_text=_("Requried, PrimaryKey none-editable"),
- db_index=True,
- )
- number = SerialField(
- primary_key=False,
- editable=False,
- help_text=_("Auto Increment Number"),
- verbose_name=_("Number"),
- #null=True
- )
- def forwards(apps, schema_editor):
- if schema_editor.connection.alias == 'default':
- return migrations.RunSQL(
- "ALTER SEQUENCE app_name_mymodel_number_seq RESTART WITH 100000"
- )
- class Migration(migrations.Migration):
- dependencies = [
- ('activities', '0001_initial'),
- ]
- operations = [
- migrations.RunPython(forwards)
- ]
Add Comment
Please, Sign In to add comment