Ticket #3538: filefield_basename_trunk.diff

File filefield_basename_trunk.diff, 1.4 KB (added by Herbert Poul <herbert.poul@…>, 18 years ago)

simple patch for latest svn trunk

  • django/db/models/base.py

     
    313313            return os.path.join(settings.MEDIA_ROOT, getattr(self, field.attname))
    314314        return ''
    315315
     316    def _get_FIELD_basename(self, field):
     317        if getattr(self, field.attname): # value is not blank
     318            return os.path.basename( self._get_FIELD_filename(field) )
     319        return ''
     320
    316321    def _get_FIELD_url(self, field):
    317322        if getattr(self, field.attname): # value is not blank
    318323            import urlparse
  • django/db/models/fields/__init__.py

     
    631631        setattr(cls, 'get_%s_filename' % self.name, curry(cls._get_FIELD_filename, field=self))
    632632        setattr(cls, 'get_%s_url' % self.name, curry(cls._get_FIELD_url, field=self))
    633633        setattr(cls, 'get_%s_size' % self.name, curry(cls._get_FIELD_size, field=self))
     634        setattr(cls, 'get_%s_basename' % self.name, curry(cls._get_FIELD_basename, field=self))
    634635        setattr(cls, 'save_%s_file' % self.name, lambda instance, filename, raw_contents: instance._save_FIELD_file(self, filename, raw_contents))
    635636        dispatcher.connect(self.delete_file, signal=signals.post_delete, sender=cls)
    636637
Back to Top