django-modeltranslation icon indicating copy to clipboard operation
django-modeltranslation copied to clipboard

django-modeltranslation TranslationAdmin does validate unique_together

Open malexeev opened this issue 10 years ago • 3 comments

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?

malexeev avatar Jul 24 '14 10:07 malexeev

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?

zlorf avatar Jul 24 '14 15:07 zlorf

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',)

EnriqueSoria avatar Feb 25 '20 13:02 EnriqueSoria

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

last-partizan avatar Feb 26 '20 11:02 last-partizan