You are here: Home / What do you need? / Help and documentation / Plone Info / Orderable reference fields

Orderable reference fields

by Darrell Kingsley last modified Mar 13, 2014 01:05 PM
Reference fields are not orderable, but you can do something similar to get the same effect.

I'm not 100% sure, but reading between the lines, it looks as though reference fields *might* have been sortable/orderable in Plone 2.x. They certainly aren't with Plone 3.x and 4.x.

I found references on the web to adding the tagged value allow_sorting=True to the reference browser widget to make it sortable, but while this added up/down arrows, which moved the items up and down, the changes did not "stick" when saved. This may well be because you always needed to use OrderableReferenceField instead of ReferenceField, and I just didn't know about it.

Adding OrderableReferenceField v1.2 beta to the products directory and installing it as normal via the quickinstaller worked. Version 1.1 didn't seem to work, as it was not backward compatible with ReferenceField, so I couldn't port existing data to it.

The other thing to bear in mind is that Products.ReferenceBrowserWidget has been replaced by archetypes.referencebrowserwidget, so the import call is now:

from archetypes.referencebrowserwidget import ReferenceBrowserWidget

The changes to the content type class overall are roughly as follows:

from Products.OrderableReferenceField import OrderableReferenceField
from archetypes.referencebrowserwidget import ReferenceBrowserWidget



 So the content type imports the new field class and uses it instead of ReferenceField in the schema.