#33763: Django admin TabularInline in a Multiple databases context
-------------------------------------+-------------------------------------
               Reporter:  moccand    |          Owner:  nobody
                   Type:             |         Status:  new
  Uncategorized                      |
              Component:             |        Version:  3.2
  contrib.admin                      |       Keywords:  admin.TabularInline
               Severity:  Normal     |  admin multiple database
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 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

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33763>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070181238a8017-412d4529-8b44-4c84-8b18-1a73693da657-000000%40eu-central-1.amazonses.com.

Reply via email to