- Author:
- magik_cypress
- Posted:
- March 9, 2012
- Language:
- Python
- Version:
- Not specified
- Score:
- 0 (after 0 ratings)
Save attachment on couchdb document
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #!/usr/bin/env python
import os, sys, datetime, getpass
from couchdbkit import *
path = '/tmp/motion'
# model
class MotionCouchdb(Document):
author = StringProperty()
content = StringProperty()
date = DateTimeProperty()
# server object
server = Server('http://127.0.0.1:5984/')
# create database
db = server.get_or_create_db("motion_couchdb")
# associate MotionCouchdb to the db
MotionCouchdb.set_db(db)
# create a new motion
motion = MotionCouchdb(
author=getpass.getuser(),
content="suck video",
date=datetime.datetime.utcnow()
)
# save it.
motion.save()
# save files
files = os.listdir(path)
file = [f for f in files if f.endswith('.jpg')]
for f in file:
read_image = open('%s/%s' % (path, f), 'r')
motion.put_attachment(read_image, f)
|
More like this
- Template tag - list punctuation for a list of items by shapiromatron 11 months, 2 weeks ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 11 months, 3 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 6 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 7 months ago
- Help text hyperlinks by sa2812 1 year, 7 months ago
Comments
Please login first before commenting.