'Django admin TabularInline and unique_together error 'dict' object has no attribute 'is_hidden'

my models:
model.py

class ModelA(Model):
    name = models.CharField('Name')


class ModelB(Model):
    model_a = models.ForeignKey(
        ModelA,
        on_delete=models.SET_NULL,
        verbose_name='modelA',
    )
   code = models.CharField('code')

   class Meta:
        unique_together = ('code', 'model_a',)

In my admin.py:

class ModelBInline(admin.TabularInline):
    model = ModelB
    fields = ('code', )

@admin.register(ModelA)
class ModelAAdmin(admin.ModelAdmin):
    list_display = (
        'name',
    )
    inlines = (ModelBInline,)

If I change the code in TabularInline, and it is not unique, then I get an error:

AttributeError at /admin/add/modelA/1/change/
'dict' object has no attribute 'is_hidden'

How to solve this problem?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source