﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
33763	Django admin TabularInline in a Multiple databases context	moccand	nobody	"All my models are stored in a dedicated database. Django admin is used as ""backoffice"".

The id fields are set in all my models, and Class meta define for each model the targeted table.


{{{
    class MyModel(models.Model):
        id = models.IntegerField(primary_key=True)
        ...
        class Meta:
            managed = False
            db_table = '__mymodel_table'
            app_label = 'catalog'

}}}


So for my models i override the save methode in order to use the sequences and autoincrement already in the external database :


{{{
def save(self, *args, **kwargs):
    if not self.id :
        self.id = getNextId(""__mymodel_id_seq"")
    super(MyModel, self).save(*args, **kwargs)
}}}


the getNetId function is :


{{{
def getNextId(sequence):
    cursor = connections['catalogu'].cursor()
    try :
        with cursor as cursor:
            cursor.execute(""select nextval('{}'::regclass)"".format(sequence))
            result = cursor.fetchall()
            return result[0][0]
    except :
        return None
}}}



In addition all my modelAdmin (except the TabularInline) inherite from :


{{{
class MultiDBModelAdmin(admin.ModelAdmin):
    # A handy constant for the name of the alternate database.
    using = 'catalog'
}}}



My TabularInLine :


{{{
class MyModelAdminInline(admin.TabularInline):
    model = MyModel
    fields = ['id', 'titre_classe', 'valeur_texte', 'valeur_min', 'valeur_max', 'id_style', 'ordre', 'rayon', 'style_css',]
}}}


and it is used in an other Admin :


{{{
MySecondModelAdmin.inlines = [MyModelAdminInline,]
}}}


With the TabularInline models it seems i must set the id fields manually.

If let it blank : i get a validation error and the field id is shown in red
If set it readonly : i get the same error
If not shown in the inline : error too ... 
But setting manualy a good value for the id it works fine.

I think all those 4 cases should work the same : the model save() method should be applied
"	Uncategorized	closed	contrib.admin	3.2	Normal	invalid	admin.TabularInline admin multiple database		Unreviewed	0	0	0	0	0	0
