-class Attribute(models.Model):
- entity_content_type = models.ForeignKey(ContentType, verbose_name='Entity type')
- entity_object_id = models.PositiveIntegerField(verbose_name='Entity ID')
- entity = generic.GenericForeignKey('entity_content_type', 'entity_object_id')
- key = models.CharField(max_length=255)
- json_value = models.TextField(verbose_name='Value (JSON)', help_text='This value must be valid JSON.')
+class JSONValue(models.Model):
+ value = JSONField() #verbose_name='Value (JSON)', help_text='This value must be valid JSON.')
+
+ def __unicode__(self):
+ return self.value_json
+
+ def value_formfield(self, *args, **kwargs):
+ kwargs['initial'] = self.value_json
+ return self._meta.get_field('value').formfield(*args, **kwargs)
+
+ class Meta:
+ app_label = 'philo'
+
+
+class ForeignKeyValue(models.Model):
+ content_type = models.ForeignKey(ContentType, related_name='foreign_key_value_set', limit_choices_to=value_content_type_limiter, verbose_name='Value type', null=True, blank=True)
+ object_id = models.PositiveIntegerField(verbose_name='Value ID', null=True, blank=True)
+ value = generic.GenericForeignKey()
+
+ def __unicode__(self):
+ return unicode(self.value)
+
+ def value_formfield(self, form_class=forms.ModelChoiceField, **kwargs):
+ if self.content_type is None:
+ return None
+ kwargs.update({'initial': self.object_id, 'required': False})
+ return form_class(self.content_type.model_class()._default_manager.all(), **kwargs)
+
+ class Meta:
+ app_label = 'philo'
+
+
+class ManyToManyValue(models.Model):
+ content_type = models.ForeignKey(ContentType, related_name='many_to_many_value_set', limit_choices_to=value_content_type_limiter, verbose_name='Value type', null=True, blank=True)
+ object_ids = models.CommaSeparatedIntegerField(max_length=300, verbose_name='Value IDs', null=True, blank=True)