Last active
January 27, 2016 22:43
-
-
Save mountcedar/85e76e70e7cb888ea540 to your computer and use it in GitHub Desktop.
mongodbを用いたPythonクラスインスタンスのdumpとrestoreとquery検索 ref: http://qiita.com/mountcedar/items/f63006a6d5d5e14acc93
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy | |
import logging | |
from datetime import datetime | |
from dbarchive import Base | |
class Sample(Base): | |
def __init__(self, maxval=10): | |
self.base = "hoge" | |
self.bin = numpy.arange(maxval) | |
self.created = datetime.now() | |
print 'create sample instance' | |
sample01 = Sample(10) | |
sample01.save() | |
sample02 = Sample(3) | |
sample02.save() | |
for sample in Sample.objects.all(): | |
print 'sample: ', type(sample) | |
print '\tbase: ', sample.base | |
print '\tbin: ', sample.bin | |
print '\tcreated: ', sample.created | |
sample01.bin = numpy.arange(20) | |
sample01.save() | |
for sample in Sample.objects.all(): | |
print 'sample: ', type(sample) | |
print '\tbase: ', sample.base | |
print '\tbin: ', sample.bin | |
print '\tcreated: ', sample.created | |
print "all task completed" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Sample(Base): | |
def __init__(self, maxval=10): | |
self.base = "hoge" | |
self.bin = numpy.arange(maxval) | |
self.created = datetime.now() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print 'create sample instance' | |
sample01 = Sample(10) | |
sample01.save() | |
sample02 = Sample(3) | |
sample02.save() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for sample in Sample.objects.all(): | |
print 'sample: ', type(sample) | |
print '\tbase: ', sample.base | |
print '\tbin: ', sample.bin | |
print '\tcreated: ', sample.created |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment