|
@@ -146,8 +146,10 @@ class CustomField(models.Model):
|
|
# Read date as YYYY-MM-DD
|
|
# Read date as YYYY-MM-DD
|
|
return date(*[int(n) for n in serialized_value.split('-')])
|
|
return date(*[int(n) for n in serialized_value.split('-')])
|
|
if self.type == CF_TYPE_SELECT:
|
|
if self.type == CF_TYPE_SELECT:
|
|
- # return CustomFieldChoice.objects.get(pk=int(serialized_value))
|
|
|
|
- return self.choices.get(pk=int(serialized_value))
|
|
|
|
|
|
+ try:
|
|
|
|
+ return self.choices.get(pk=int(serialized_value))
|
|
|
|
+ except CustomFieldChoice.DoesNotExist:
|
|
|
|
+ return None
|
|
return serialized_value
|
|
return serialized_value
|
|
|
|
|
|
|
|
|
|
@@ -198,6 +200,12 @@ class CustomFieldChoice(models.Model):
|
|
if self.field.type != CF_TYPE_SELECT:
|
|
if self.field.type != CF_TYPE_SELECT:
|
|
raise ValidationError("Custom field choices can only be assigned to selection fields.")
|
|
raise ValidationError("Custom field choices can only be assigned to selection fields.")
|
|
|
|
|
|
|
|
+ def delete(self, using=None, keep_parents=False):
|
|
|
|
+ # When deleting a CustomFieldChoice, delete all CustomFieldValues which point to it
|
|
|
|
+ pk = self.pk
|
|
|
|
+ super(CustomFieldChoice, self).delete(using, keep_parents)
|
|
|
|
+ CustomFieldValue.objects.filter(field__type=CF_TYPE_SELECT, serialized_value=str(pk)).delete()
|
|
|
|
+
|
|
|
|
|
|
class Graph(models.Model):
|
|
class Graph(models.Model):
|
|
type = models.PositiveSmallIntegerField(choices=GRAPH_TYPE_CHOICES)
|
|
type = models.PositiveSmallIntegerField(choices=GRAPH_TYPE_CHOICES)
|