~panosl/+junk/django-attachments

« back to all changes in this revision

Viewing changes to README.rst

  • Committer: Aaron C. de Bruyn
  • Date: 2010-01-11 05:31:21 UTC
  • Revision ID: git-v1:07dc4a4dd4d7488923eed8904910f9c1754fbe7e
Updated readme with information on attaching file from the python console

Show diffs side-by-side

added added

removed removed

Lines of Context:
132
132
 
133
133
    {% attachment_form entry %}
134
134
 
 
135
In the console:
 
136
==========
 
137
 
 
138
First, import the items you will need::
 
139
    import os
 
140
    from django.core.files import File
 
141
    from attachments.models import Attachment
 
142
    from myproject.models import Person
 
143
 
 
144
Next, retrieve the object you wish to attach to::
 
145
    me = Person.objects.get(name='aaron')
 
146
 
 
147
Now open the attachment you want from your drive using the django File object::
 
148
    mypicture = File(open('/home/aaron/mypicture.jpg', 'r'))
 
149
 
 
150
Finally, create the Attachment object and save it::
 
151
    a = Attachment()
 
152
    a.creator = me
 
153
    a.attachment_file = mypicture
 
154
    a.save()
 
155
 
135
156
Changelog:
136
157
==========
137
158