Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Fix model serialization

Patryk Zawadzki7537cfbc80dc
diff --git a/saleor/userprofile/models.py b/saleor/userprofile/models.py
index d6a01baa81..738d92a882 100644
--- a/saleor/userprofile/models.py
+++ b/saleor/userprofile/models.py
@@ -8,13 +8,16 @@ from django.forms.models import model_to_dict
from django.utils import timezone
from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import pgettext_lazy
-from django_countries.fields import CountryField
+from django_countries.fields import Country, CountryField
class AddressManager(models.Manager):
def as_data(self, address):
- return model_to_dict(address, exclude=['id', 'user'])
+ data = model_to_dict(address, exclude=['id', 'user'])
+ if isinstance(data['country'], Country):
+ data['country'] = data['country'].code
+ return data
def are_identical(self, addr1, addr2):
data1 = self.as_data(addr1)