Ver código fonte

Merge pull request #4214 from django-oscar/fixes-broken-migration

Fixes broken migration of attribute values
master
Samar Hassan 1 ano atrás
pai
commit
25092a272b
Nenhuma conta vinculada ao e-mail do autor do commit

+ 11
- 9
src/oscar/apps/catalogue/migrations/0024_remove_duplicate_attributes.py Ver arquivo

5
 from django.db.models import CharField, Count, Value
5
 from django.db.models import CharField, Count, Value
6
 from django.db.models.functions import Concat
6
 from django.db.models.functions import Concat
7
 
7
 
8
-from oscar.core.loading import get_model
9
-
10
-# Needed for calling _get_value, the historical model can't be used for that.
11
-NonHistoricalProductAttributeValue = get_model('catalogue', 'ProductAttributeValue')
12
-
13
-
14
 logger = logging.getLogger(__name__)
8
 logger = logging.getLogger(__name__)
15
 
9
 
16
 
10
 
11
+def get_value(attribute_value):
12
+    typ = attribute_value.attribute.type
13
+    field_name = "value_%s" % typ
14
+    value = getattr(attribute_value, field_name)
15
+    if hasattr(value, "all"):
16
+        value = value.all()
17
+    return value
18
+
17
 def remove_duplicate_attributes(apps, schema_editor):
19
 def remove_duplicate_attributes(apps, schema_editor):
18
     """
20
     """
19
     Removes duplicate attributes that have the same code and product class.
21
     Removes duplicate attributes that have the same code and product class.
83
                     """ % (
85
                     """ % (
84
                         product.id,
86
                         product.id,
85
                         attribute.code,
87
                         attribute.code,
86
-                        NonHistoricalProductAttributeValue._get_value(to_be_used_attribute_value),
87
-                        NonHistoricalProductAttributeValue._get_value(attribute_value)
88
+                        get_value(to_be_used_attribute_value),
89
+                        get_value(attribute_value)
88
                     )
90
                     )
89
                     logger.warning(msg)
91
                     logger.warning(msg)
90
 
92
 
101
 
103
 
102
     operations = [
104
     operations = [
103
         migrations.RunPython(remove_duplicate_attributes, migrations.RunPython.noop)
105
         migrations.RunPython(remove_duplicate_attributes, migrations.RunPython.noop)
104
-    ]
106
+    ]

Carregando…
Cancelar
Salvar