#3297: newforms: Implement FileField and ImageField
---------------------------------------+------------------------------------
   Reporter:  [EMAIL PROTECTED]  |                Owner:  adrian         
     Status:  reopened                 |            Component:  django.newforms
    Version:  SVN                      |           Resolution:                 
   Keywords:  newforms                 |                Stage:  Accepted       
  Has_patch:  1                        |           Needs_docs:  0              
Needs_tests:  0                        |   Needs_better_patch:  0              
---------------------------------------+------------------------------------
Comment (by [EMAIL PROTECTED]):

 I'd like to point out that there is the FileInput widget, which is fine
 for _uploading_ a file, but for _displaying_ a file or an image, on should
 display a link/thumbnail/whatever.
 
 So I made this little widget:
 
 {{{
 from django.newforms.widgets import Widget, smart_unicode
 import os
 
 class File(Widget):
     def render(self, name, value, attrs=None):
         if value is None or value=='': return u'No file uploaded'
 
         if value != '': value = smart_unicode(value) # Only add the
 'value' attribute if a value is non-empty.
 
         return u'<a href="%s">%s</a>' % (value,os.path.basename(value))
 }}}
 
 It's very basic, and needs to be passed the absolute url of a file (easy
 for models using get_FIELD_url). But it works.
 
 To use it, I define a separate field that uses it, and I manually set it
 to the model's data.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/3297#comment:29>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to