Add BigAutoField for BlockCompletion primary key.
This commit is contained in:
@@ -12,4 +12,3 @@ class CompletionAppConfig(AppConfig):
|
||||
"""
|
||||
name = 'lms.djangoapps.completion'
|
||||
verbose_name = 'Completion'
|
||||
pass
|
||||
|
||||
@@ -2,12 +2,19 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import lms.djangoapps.completion.models
|
||||
import django.utils.timezone
|
||||
from django.conf import settings
|
||||
import model_utils.fields
|
||||
|
||||
import lms.djangoapps.completion.models
|
||||
import openedx.core.djangoapps.xmodule_django.models
|
||||
|
||||
# pylint: disable=ungrouped-imports
|
||||
try:
|
||||
from django.models import BigAutoField # New in django 1.10
|
||||
except ImportError:
|
||||
from openedx.core.djangolib.fields import BigAutoField
|
||||
# pylint: enable=ungrouped-imports
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
@@ -19,9 +26,9 @@ class Migration(migrations.Migration):
|
||||
migrations.CreateModel(
|
||||
name='BlockCompletion',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
||||
('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, verbose_name='created', editable=False)),
|
||||
('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, verbose_name='modified', editable=False)),
|
||||
('id', BigAutoField(serialize=False, primary_key=True)),
|
||||
('course_key', openedx.core.djangoapps.xmodule_django.models.CourseKeyField(max_length=255)),
|
||||
('block_key', openedx.core.djangoapps.xmodule_django.models.UsageKeyField(max_length=255)),
|
||||
('block_type', models.CharField(max_length=64)),
|
||||
@@ -35,9 +42,6 @@ class Migration(migrations.Migration):
|
||||
),
|
||||
migrations.AlterIndexTogether(
|
||||
name='blockcompletion',
|
||||
index_together=set([
|
||||
('course_key', 'block_type', 'user'),
|
||||
('user', 'course_key', 'modified'),
|
||||
]),
|
||||
index_together=set([('course_key', 'block_type', 'user'), ('user', 'course_key', 'modified')]),
|
||||
),
|
||||
]
|
||||
|
||||
@@ -13,6 +13,13 @@ from opaque_keys.edx.keys import CourseKey
|
||||
|
||||
from openedx.core.djangoapps.xmodule_django.models import CourseKeyField, UsageKeyField
|
||||
|
||||
# pylint: disable=ungrouped-imports
|
||||
try:
|
||||
from django.models import BigAutoField # New in django 1.10
|
||||
except ImportError:
|
||||
from openedx.core.djangolib.fields import BigAutoField
|
||||
# pylint: enable=ungrouped-imports
|
||||
|
||||
|
||||
def validate_percent(value):
|
||||
"""
|
||||
@@ -106,6 +113,7 @@ class BlockCompletion(TimeStampedModel, models.Model):
|
||||
only track binary completion, where 1.0 indicates that the block is
|
||||
complete, and 0.0 indicates that the block is incomplete.
|
||||
"""
|
||||
id = BigAutoField(primary_key=True) # pylint: disable=invalid-name
|
||||
user = models.ForeignKey(User)
|
||||
course_key = CourseKeyField(max_length=255)
|
||||
block_key = UsageKeyField(max_length=255)
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user