Python 使用objectid从image.file获取图像
我对mongoengine有问题。我在image.files集合中获取图像的objectid。如何在django中获取图像,就像image.files.objects(pk=objectid.first()?Python 使用objectid从image.file获取图像,python,django,image,mongodb,mongoengine,Python,Django,Image,Mongodb,Mongoengine,我对mongoengine有问题。我在image.files集合中获取图像的objectid。如何在django中获取图像,就像image.files.objects(pk=objectid.first()? 是否有用于此的API?您只需查询网格id并返回匹配的文档,如下所示: class TestImage(Document): image = ImageField() TestImage.drop_collection() t = TestImage() t.image1.pu
是否有用于此的API?您只需查询
网格id
并返回匹配的文档,如下所示:
class TestImage(Document):
image = ImageField()
TestImage.drop_collection()
t = TestImage()
t.image1.put(open(TEST_IMAGE_PATH, 'rb'))
t.save()
test = TestImage.objects.first()
grid_id = test.image1.grid_id
self.assertEqual(1, TestImage.objects(image1=grid_id).count())