Commits

Anonymous committed 5a232d3

Fixed Meta option override causeing unique_together to be lost

  • Participants
  • Parent commits df90312

Comments (0)

Files changed (1)

i18n_model/models.py

             if field.name in fields:
                 attrs[field.name] = copy.deepcopy(field)
 
+        # Add unique_together to Meta
+        if hasattr(attr_meta, 'unique_together'):
+            if type(attrs['Meta'].unique_together[0]) in (str, unicode):
+                attrs['Meta'].unique_together = (
+                    attrs['Meta'].unique_together,
+                    ('i18n_source', 'i18n_language')
+                )
+            else:
+                attrs['Meta'].unique_together += (
+                    'i18n_source',
+                    'i18n_language'
+                )
+        else:
+            attrs['Meta'].unique_together = ('i18n_source', 'i18n_language')
+
         # Let's also add a reference to the original model
         attrs['i18n_source'] = models.ForeignKey(
             source,
 
     class Meta:
         abstract = True
-        unique_together = ('i18n_source', 'i18n_language')