Ticket #15651: filepath_sort.diff

File filepath_sort.diff, 1.8 KB (added by FunkyBob, 14 years ago)
  • django/db/models/fields/__init__.py

     
    817817class FilePathField(Field):
    818818    description = _("File path")
    819819
    820     def __init__(self, verbose_name=None, name=None, path='', match=None, recursive=False, **kwargs):
    821         self.path, self.match, self.recursive = path, match, recursive
     820    def __init__(self, verbose_name=None, name=None, path='', match=None, recursive=False, sort=False, **kwargs):
     821        self.path, self.match, self.recursive, self.sort = path, match, recursive, sort
    822822        kwargs['max_length'] = kwargs.get('max_length', 100)
    823823        Field.__init__(self, verbose_name, name, **kwargs)
    824824
  • django/forms/fields.py

     
    880880class FilePathField(ChoiceField):
    881881    def __init__(self, path, match=None, recursive=False, required=True,
    882882                 widget=None, label=None, initial=None, help_text=None,
    883                  *args, **kwargs):
     883                 sort=False, *args, **kwargs):
    884884        self.path, self.match, self.recursive = path, match, recursive
    885885        super(FilePathField, self).__init__(choices=(), required=required,
    886886            widget=widget, label=label, initial=initial, help_text=help_text,
     
    909909            except OSError:
    910910                pass
    911911
     912        if sort:
     913            if callable(sort):
     914                self.choices = sort(self, self.choices)
     915            else:
     916                self.choices.sort(key=lambda x: x[1])
     917
    912918        self.widget.choices = self.choices
    913919
    914920class SplitDateTimeField(MultiValueField):
Back to Top