Commits

Anonymous committed 43050bf Draft

updating Trac to allow ticket fields to store references to resources using a different primary key than the name - #towards #110

Comments (0)

Files changed (1)

trac/ticket/api.py

         (rank, field)
         where field is a dictionary that defines:
             * name: the field name 
+            * pk: the primary key of the field table
             * label: the label to display, preferably wrapped with N_()
             * cls: the model describing the field
         the following keys can also usefully be defined:
         for rank, field in selects:
             cls = field['cls']
             name = field['name']
-            options = [val.name for val in cls.select(self.env, db=db)]
+            pk_field = field.get('pk', 'name')
+            options = [getattr(val, pk_field)
+                       for val in cls.select(self.env, db=db)]
+
             if not options:
                 # Fields without possible values are treated as if they didn't
                 # exist