Here it's the code working :)

-----------------------
class TableDataGrid(grids.DataGrid):
  # This would be different for each instance of grids.DataGrid
   sortable = ['pk', 'en_name', 'region']

   model = models.Country
   meta = model._meta

   #data = {}  # !!! To delete
   fields = []
   for f in meta._fields():
      name = f.name
      if 'id' in name:
         name = 'pk'
      fields.append(name)

      if name in sortable:
         exec("%s = grids.Column(%r, sortable=True)" %
              (name, unicode(f.verbose_name)))
      else:
         exec("%s = grids.Column(%r)" % (name, unicode
(f.verbose_name)))

      # ### !!! To delete
      # I'm using exec() because with a dictionary it says:
      # 'list index out of range'
      #data[name] = "grids.Column(%r)" % unicode(f.verbose_name)
      # ### !!!

   def __init__(self, request):
      grids.DataGrid.__init__(self, request, self.model.objects.all(),
                              self.meta.verbose_name_plural.title)
      self.default_sort = self.meta.ordering
      self.default_columns = self.fields
-----------------------

On 22 feb, 11:02, Christian Hammond <chip...@chipx86.com> wrote:
> Providing a custom DataGrid like this would be a nice addition to Djblets. I
> probably won't be able to spend any time fine-tuning this, but it looks like
> you have a good start. If we got this polished up, I'd definitely include it
> in Djblets.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"reviewboard" group.
To post to this group, send email to reviewboard@googlegroups.com
To unsubscribe from this group, send email to 
reviewboard+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/reviewboard?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to