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
e8cb7b77
Commit
e8cb7b77
authored
Jul 31, 2017
by
Tyler Hallada
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Custom one-to-one field for ref to custom id field
parent
6b97c1bd
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
3 deletions
+24
-3
lms/djangoapps/coursewarehistoryextended/fields.py
+19
-0
lms/djangoapps/grades/migrations/0013_persistentsubsectiongradeoverride.py
+3
-1
lms/djangoapps/grades/models.py
+2
-2
No files found.
lms/djangoapps/coursewarehistoryextended/fields.py
View file @
e8cb7b77
...
@@ -3,6 +3,7 @@ Custom fields for use in the coursewarehistoryextended django app.
...
@@ -3,6 +3,7 @@ Custom fields for use in the coursewarehistoryextended django app.
"""
"""
from
django.db.models.fields
import
AutoField
from
django.db.models.fields
import
AutoField
from
django.db.models.fields.related
import
OneToOneField
class
UnsignedBigIntAutoField
(
AutoField
):
class
UnsignedBigIntAutoField
(
AutoField
):
...
@@ -24,6 +25,7 @@ class UnsignedBigIntAutoField(AutoField):
...
@@ -24,6 +25,7 @@ class UnsignedBigIntAutoField(AutoField):
else
:
else
:
return
None
return
None
# rel_db_type was added in Django 1.10. For versions before, use UnsignedBigIntOneToOneField.
def
rel_db_type
(
self
,
connection
):
def
rel_db_type
(
self
,
connection
):
if
connection
.
settings_dict
[
'ENGINE'
]
==
'django.db.backends.mysql'
:
if
connection
.
settings_dict
[
'ENGINE'
]
==
'django.db.backends.mysql'
:
return
"bigint UNSIGNED"
return
"bigint UNSIGNED"
...
@@ -33,3 +35,20 @@ class UnsignedBigIntAutoField(AutoField):
...
@@ -33,3 +35,20 @@ class UnsignedBigIntAutoField(AutoField):
return
"BIGSERIAL"
return
"BIGSERIAL"
else
:
else
:
return
None
return
None
class
UnsignedBigIntOneToOneField
(
OneToOneField
):
"""
An unsigned 8-byte integer one-to-one foreign key to a unsigned 8-byte integer id field.
Should only be necessary for versions of Django < 1.10.
"""
def
db_type
(
self
,
connection
):
if
connection
.
settings_dict
[
'ENGINE'
]
==
'django.db.backends.mysql'
:
return
"bigint UNSIGNED"
elif
connection
.
settings_dict
[
'ENGINE'
]
==
'django.db.backends.sqlite3'
:
return
"integer"
elif
connection
.
settings_dict
[
'ENGINE'
]
==
'django.db.backends.postgresql_psycopg2'
:
return
"BIGSERIAL"
else
:
return
None
lms/djangoapps/grades/migrations/0013_persistentsubsectiongradeoverride.py
View file @
e8cb7b77
...
@@ -3,6 +3,8 @@ from __future__ import unicode_literals
...
@@ -3,6 +3,8 @@ from __future__ import unicode_literals
from
django.db
import
migrations
,
models
from
django.db
import
migrations
,
models
from
coursewarehistoryextended.fields
import
UnsignedBigIntOneToOneField
class
Migration
(
migrations
.
Migration
):
class
Migration
(
migrations
.
Migration
):
...
@@ -21,7 +23,7 @@ class Migration(migrations.Migration):
...
@@ -21,7 +23,7 @@ class Migration(migrations.Migration):
(
'possible_all_override'
,
models
.
FloatField
(
null
=
True
,
blank
=
True
)),
(
'possible_all_override'
,
models
.
FloatField
(
null
=
True
,
blank
=
True
)),
(
'earned_graded_override'
,
models
.
FloatField
(
null
=
True
,
blank
=
True
)),
(
'earned_graded_override'
,
models
.
FloatField
(
null
=
True
,
blank
=
True
)),
(
'possible_graded_override'
,
models
.
FloatField
(
null
=
True
,
blank
=
True
)),
(
'possible_graded_override'
,
models
.
FloatField
(
null
=
True
,
blank
=
True
)),
(
'grade'
,
models
.
OneToOneField
(
related_name
=
'override'
,
to
=
'grades.PersistentSubsectionGrade'
)),
(
'grade'
,
UnsignedBigInt
OneToOneField
(
related_name
=
'override'
,
to
=
'grades.PersistentSubsectionGrade'
)),
],
],
),
),
]
]
lms/djangoapps/grades/models.py
View file @
e8cb7b77
...
@@ -20,7 +20,7 @@ from lazy import lazy
...
@@ -20,7 +20,7 @@ from lazy import lazy
from
model_utils.models
import
TimeStampedModel
from
model_utils.models
import
TimeStampedModel
from
opaque_keys.edx.keys
import
CourseKey
,
UsageKey
from
opaque_keys.edx.keys
import
CourseKey
,
UsageKey
from
coursewarehistoryextended.fields
import
UnsignedBigIntAutoField
from
coursewarehistoryextended.fields
import
UnsignedBigIntAutoField
,
UnsignedBigIntOneToOneField
from
eventtracking
import
tracker
from
eventtracking
import
tracker
from
openedx.core.djangoapps.xmodule_django.models
import
CourseKeyField
,
UsageKeyField
from
openedx.core.djangoapps.xmodule_django.models
import
CourseKeyField
,
UsageKeyField
from
request_cache
import
get_cache
from
request_cache
import
get_cache
...
@@ -693,7 +693,7 @@ class PersistentSubsectionGradeOverride(models.Model):
...
@@ -693,7 +693,7 @@ class PersistentSubsectionGradeOverride(models.Model):
class
Meta
(
object
):
class
Meta
(
object
):
app_label
=
"grades"
app_label
=
"grades"
grade
=
models
.
OneToOneField
(
PersistentSubsectionGrade
,
related_name
=
'override'
)
grade
=
UnsignedBigInt
OneToOneField
(
PersistentSubsectionGrade
,
related_name
=
'override'
)
# Created/modified timestamps prevent race-conditions when using with async rescoring tasks
# Created/modified timestamps prevent race-conditions when using with async rescoring tasks
created
=
models
.
DateTimeField
(
auto_now_add
=
True
,
db_index
=
True
)
created
=
models
.
DateTimeField
(
auto_now_add
=
True
,
db_index
=
True
)
...
...
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