Turbogears 2 admin interface non auto-interger primary keys

31 views
Skip to first unread message

Jacob Lister

unread,
Jun 26, 2015, 3:42:22 AM6/26/15
to turbo...@googlegroups.com
I've been looking at Turbogears recently after getting frustrated with limitations in the Django ORM, specifically around using compound primary keys.

I'm pleased to see that the Turbogears admin interface will allow me to edit tables keyed on a compound (multi column) primary key and handles them well (maps to a URL like 'http://host.com/admin/tablename/columnA/columnB/edit') , 

however the interface only allow me to edit and delete records, not create new ones. (This is true for any non auto-integer primary key, not just multi column ones)

Is there any way to make this work?

Alessandro Molina

unread,
Jun 26, 2015, 10:47:42 AM6/26/15
to TurboGears
On Fri, Jun 26, 2015 at 7:28 AM, Jacob Lister <jacob.h...@gmail.com> wrote:
I've been looking at Turbogears recently after getting frustrated with limitations in the Django ORM, specifically around using compound primary keys.

Great! I never needed to use the compount primary keys feature on production, so it's great that we finally have someone able to provide feedbacks on it :D 
 
however the interface only allow me to edit and delete records, not create new ones. (This is true for any non auto-integer primary key, not just multi column ones)

What do you mean regarding that it doesn't allow to create new records? What does it happen? 

Alessandro Molina

unread,
Jun 26, 2015, 11:15:27 AM6/26/15
to TurboGears


On Fri, Jun 26, 2015 at 4:47 PM, Alessandro Molina <alessand...@gmail.com> wrote:

however the interface only allow me to edit and delete records, not create new ones. (This is true for any non auto-integer primary key, not just multi column ones)

What do you mean regarding that it doesn't allow to create new records? What does it happen? 

Ok, just saw what's your problem.
Looks like most of SPROX code is meant to work with composite primary keys in relations, but the form generation part doesn't support composite primary keys.

Both EditableForm and AddRecordForm actually rely on get_primary_field method of the provider, which in case of multiple primary keys only returns the first.
So both of them actually consider only the first field to be the primary key and the second one as a plain field.

This leads to odd behaviours, like in case of edit you can only change the second field of the primary key and in case of new the first field is missing at all as it is considered to be automatically generated. 

I suppose New works only if you provide a default value for both fields, as it expects the primary key to be automatic.

Jacob Lister

unread,
Jun 29, 2015, 1:37:54 AM6/29/15
to turbo...@googlegroups.com
Yes, it appears the admin interface handles any models with a non auto-integer primary key poorly for create operations - 
in all cases it:
* displays columns marked primary key as disabled when editing
* doesn't display fields marked primary field on create, and leaves them to default on the database query it makes

Which will work fine for auto-integer keys, but not otherwise.

Still I'm pretty impresses the admin interface can handle composite primary keys otherwise (for edit/delete), might have a look around at the SPROX code, as this limitation sounds solvable    

Alessandro Molina

unread,
Jul 14, 2015, 12:29:08 PM7/14/15
to TurboGears
Sprox 0.9.7 has been released with a preliminary basic support for compound primary keys in forms: https://plus.google.com/+turbogears/posts/GnmT5HwxW6t

The support is far for being complete, but at least it is possible to create and edit entries with a compound primary key in tgext.admin now.

--
You received this message because you are subscribed to the Google Groups "TurboGears" group.
To unsubscribe from this group and stop receiving emails from it, send an email to turbogears+...@googlegroups.com.
To post to this group, send email to turbo...@googlegroups.com.
Visit this group at http://groups.google.com/group/turbogears.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages