2013-06-21 35 views
0

我使用mongoengine在mongodb的GridFS中插入圖像。 插入一切正常,但我現在想刪除,我沒有得到。 我使用的版本0.8.2,我mongoengine這樣做:Mongoengine刪除文件gridfs

class Animal(Document): 

     genus = StringField() 
     family = StringField() 
     photo = FileField() 

marmot = Animal(genus='Marmota') 

marmot.photo.delete() 

只有他沒有刪除任何東西或提供錯誤。 我在做什麼錯?有人可以幫助我嗎?

+0

什麼是錯誤? – Ross

+0

試過了,得到了同樣的結果。沒有。 – evermean

回答

0

我設法刪除,這樣的:

marmot = Animal.objects.get(id='51c80fb28774a715dc0481ae') 
marmot.photo.delete() 

The issue is that I'm doing my upload to GridFS with the following code: 

    if request.method == 'POST': 
         
        my_painting = Movie.objects.get(id=id) 
                 
        files = [] 
        for f in request.FILES.getlist('file'): 
           mf = mongoengine.fields.GridFSProxy() 
           mf.put(f, filename=f.name, legend='Oi') 

           files.append(mf) 
           print files 
           my_painting.MovieCover = files 
        my_painting.save() 

插入沒關係。

但是當我刪除,使用相同的上述給了我以下錯誤: 「BaseList」對象有沒有屬性「刪除」

有人能幫助我嗎?

+0

我設法解決的問題是使用滾動瀏覽圖片並逐個刪除。 我想知道如何通過它的id刪除單個圖像?有人可以幫助我嗎? – Helio