Add BigAutoField for BlockCompletion primary key.

This commit is contained in:
J. Cliff Dyer
2017-10-10 21:43:07 -04:00
parent 6f89157d62
commit 4ab64f76a2
4 changed files with 49 additions and 8 deletions

View File

@@ -5,7 +5,9 @@ from django.db import models
class CharNullField(models.CharField):
"""CharField that stores NULL but returns ''"""
"""
CharField that stores NULL but returns ''
"""
description = "CharField that stores NULL but returns ''"
@@ -26,3 +28,31 @@ class CharNullField(models.CharField):
return None
else:
return value
class BigAutoField(models.AutoField):
"""
AutoField that uses BigIntegers.
This exists in Django as of version 1.10.
"""
def db_type(self, connection):
"""
The type of the field to insert into the database.
"""
conn_module = type(connection).__module__
if "mysql" in conn_module:
return "bigint AUTO_INCREMENT"
elif "postgres" in conn_module:
return "bigserial"
else:
return super(BigAutoField, self).db_type(connection)
def rel_db_type(self, connection):
"""
The type to be used by relations pointing to this field.
Not used until Django 1.10.
"""
return "bigint"