Added bulk editing capability for custom fields

This commit is contained in:
Jeremy Stretch
2016-08-16 14:57:04 -04:00
parent a9a55350df
commit 7d879bb0dc
11 changed files with 143 additions and 227 deletions

View File

@@ -131,14 +131,22 @@ class CustomFieldValue(models.Model):
if self.field.type == CF_TYPE_INTEGER:
self.val_int = value
elif self.field.type == CF_TYPE_BOOLEAN:
self.val_int = bool(value) if value else None
self.val_int = int(bool(value)) if value is not None else None
elif self.field.type == CF_TYPE_DATE:
self.val_date = value
elif self.field.type == CF_TYPE_SELECT:
self.val_int = value.id
# Could be ModelChoiceField or TypedChoiceField
self.val_int = value.id if hasattr(value, 'id') else value
else:
self.val_char = value
def save(self, *args, **kwargs):
if (self.field.type == CF_TYPE_TEXT and self.value == '') or self.value is None:
if self.pk:
self.delete()
else:
super(CustomFieldValue, self).save(*args, **kwargs)
class CustomFieldChoice(models.Model):
field = models.ForeignKey('CustomField', related_name='choices', limit_choices_to={'type': CF_TYPE_SELECT},