Merge pull request #12645 from CredoReference/more-than-one-lti-consumer-with-empty-instance-guid

Ability to create two or more LTI consumers through the Django admin with an empty instance_guid field
This commit is contained in:
Douglas Hall
2016-11-21 14:04:21 -05:00
committed by GitHub
4 changed files with 74 additions and 1 deletions

View File

@@ -0,0 +1,28 @@
"""
Custom Django fields.
"""
from django.db import models
class CharNullField(models.CharField):
"""CharField that stores NULL but returns ''"""
description = "CharField that stores NULL but returns ''"
def to_python(self, value):
"""Converts the value into the correct Python object."""
if isinstance(value, models.CharField):
return value
if value is None:
return ""
else:
return value
def get_db_prep_value(self, value, connection, prepared=False):
"""Converts value to a backend-specific value."""
if not prepared:
value = self.get_prep_value(value)
if value == "":
return None
else:
return value