deschler / django-modeltranslation

Translates Django models using a registration approach.
BSD 3-Clause "New" or "Revised" License
1.38k stars 257 forks source link

django-modeltranslation TranslationAdmin does validate unique_together #261

Open malexeev opened 10 years ago

malexeev commented 10 years ago

I have a model with 2 fields that are marked as unique_together. One of the fields is being translated by django-modeltranslation.

Using standard Django admin on this model works fine, it shows validation error when trying to insert duplicates. But the TranslationAdmin seems to ignore that validation. It all goes directly to the database, hitting the same database constraint (well, a unique index) crashing.

Is it a bug, or am I doing something wrong?

zlorf commented 10 years ago

Since currently unique_together is not affected it refers to original field which value is unknown.

However, validation should fail. Need to check.

Or: rewrite unique_together if contains translation fields? But how: with default language only, or with all possible combinations?

EnriqueSoria commented 4 years ago

Same problem here.

I'm working on a project and I need to translate option attribute in this model. Is there a way to manage this scenario?

class AttributeOption(models.Model):
    group = models.ForeignKey(...)
    option = models.CharField(...)
    class Meta:
        unique_together = ('group', 'option')
class AttributeOptionTranslation(TranslationOptions):
    fields = ('option',)
last-partizan commented 4 years ago

Probably it is a bug, pull-request or ideas how this should be fixed are welcomed.