Fix.
[redakcja.git] / src / catalogue / wikidata.py
index 90f1a5c..731e55f 100644 (file)
@@ -159,7 +159,16 @@ class WikidataModel(models.Model):
                 wdvalue = wdvalue.label.get(language, str(wdvalue.label))
 
             if not skip_set:
                 wdvalue = wdvalue.label.get(language, str(wdvalue.label))
 
             if not skip_set:
-                setattr(self, attname, wdvalue)
+                try:
+                    wdvalue = model_field.to_python(wdvalue)
+                except:
+                    pass
+                else:
+                    if isinstance(wdvalue, str):
+                        max_length = getattr(model_field, 'max_length', None)
+                        if max_length:
+                            wdvalue = wdvalue[:max_length]
+                    setattr(self, attname, wdvalue)
 
     def wikidata_link(self):
         if self.wikidata:
 
     def wikidata_link(self):
         if self.wikidata: