|
49 | 49 |
|
50 | 50 | from .validators import * |
51 | 51 | from .fields import EavSlugField, EavDatatypeField |
| 52 | +from .utils.utilities import Utils |
52 | 53 |
|
53 | 54 |
|
54 | 55 | class EnumValue(models.Model): |
@@ -86,7 +87,7 @@ class EnumValue(models.Model): |
86 | 87 | @python_2_unicode_compatible |
87 | 88 | def __str__(self): |
88 | 89 | return self.value |
89 | | - |
| 90 | + |
90 | 91 |
|
91 | 92 | class EnumGroup(models.Model): |
92 | 93 | ''' |
@@ -304,16 +305,15 @@ def save_value(self, entity, value): |
304 | 305 | Attribute and *entity*, it will delete that :class:`Value` object. |
305 | 306 | ''' |
306 | 307 | ct = ContentType.objects.get_for_model(entity) |
| 308 | + entity_dict = dict(entity_ct=ct, |
| 309 | + attribute=self) |
| 310 | + entity_dict[Value.entity_id_type] = entity.pk |
307 | 311 | try: |
308 | | - value_obj = self.value_set.get(entity_ct=ct, |
309 | | - entity_id=entity.pk, |
310 | | - attribute=self) |
| 312 | + value_obj = self.value_set.get(**entity_dict) |
311 | 313 | except Value.DoesNotExist: |
312 | 314 | if value == None or value == '': |
313 | 315 | return |
314 | | - value_obj = Value.objects.create(entity_ct=ct, |
315 | | - entity_id=entity.pk, |
316 | | - attribute=self) |
| 316 | + value_obj = Value.objects.create(**entity_dict) |
317 | 317 | if value == None or value == '': |
318 | 318 | value_obj.delete() |
319 | 319 | return |
@@ -347,10 +347,13 @@ class Value(models.Model): |
347 | 347 | <Value: crazy_dev_user - Favorite Drink: "red bull"> |
348 | 348 | ''' |
349 | 349 |
|
| 350 | + entity_id_type = Utils().get_eav_entity_id_type() |
| 351 | + |
350 | 352 | entity_ct = models.ForeignKey(ContentType, related_name='value_entities') |
351 | | - entity_id = models.IntegerField() |
| 353 | + entity_id = models.IntegerField(blank=True, null=True) |
| 354 | + entity_uuid = models.UUIDField(blank=True, null=True) |
352 | 355 | entity = generic.GenericForeignKey(ct_field='entity_ct', |
353 | | - fk_field='entity_id') |
| 356 | + fk_field=entity_id_type) |
354 | 357 |
|
355 | 358 | value_text = models.TextField(blank=True, null=True) |
356 | 359 | value_float = models.FloatField(blank=True, null=True) |
@@ -521,8 +524,9 @@ def get_values(self): |
521 | 524 | ''' |
522 | 525 | Get all set :class:`Value` objects for self.model |
523 | 526 | ''' |
524 | | - return Value.objects.filter(entity_ct=self.ct, |
525 | | - entity_id=self.model.pk).select_related() |
| 527 | + entiity_filter = dict(entity_ct=self.ct) |
| 528 | + entiity_filter[Value.entity_id_type] = self.model.pk |
| 529 | + return Value.objects.filter(**entiity_filter).select_related() |
526 | 530 |
|
527 | 531 | def get_all_attribute_slugs(self): |
528 | 532 | ''' |
|
0 commit comments