Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
4ab64f76
Commit
4ab64f76
authored
Oct 10, 2017
by
J. Cliff Dyer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add BigAutoField for BlockCompletion primary key.
parent
6f89157d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
8 deletions
+49
-8
lms/djangoapps/completion/apps.py
+0
-1
lms/djangoapps/completion/migrations/0001_initial.py
+10
-6
lms/djangoapps/completion/models.py
+8
-0
openedx/core/djangolib/fields.py
+31
-1
No files found.
lms/djangoapps/completion/apps.py
View file @
4ab64f76
...
...
@@ -12,4 +12,3 @@ class CompletionAppConfig(AppConfig):
"""
name
=
'lms.djangoapps.completion'
verbose_name
=
'Completion'
pass
lms/djangoapps/completion/migrations/0001_initial.py
View file @
4ab64f76
...
...
@@ -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'
)]),
),
]
lms/djangoapps/completion/models.py
View file @
4ab64f76
...
...
@@ -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
)
...
...
openedx/core/djangolib/fields.py
View file @
4ab64f76
...
...
@@ -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"
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment