0

I am using mongoengine to insert images in mongodb's GridFS. Insert everything is ok, but I now want to delete, and I'm not getting. I am using version 0.8.2 and I'm mongoengine to do so:

class Animal(Document):

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

marmot = Animal(genus='Marmota')

marmot.photo.delete()

Only he did not delete anything or gives error. What am I doing wrong? Someone can help me?

karthikr
  • 97,368
  • 26
  • 197
  • 188
Helio
  • 81
  • 4

1 Answers1

0

I managed to delete, thus:

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()

Inserts okay.

But when I delete, using the same above gives me the following error: 'BaseList' object has no attribute 'delete'

Someone can help me?

Helio
  • 81
  • 4
  • I managed to solve the problem using one is to scroll through the images and delete one by one. I wonder was how it was possible to delete single image by its id? Someone can help me? – Helio Jun 24 '13 at 16:31