Exemplo n.º 1
0
 def save(self):
   data = self.cleaned_data
   photo = Photo()
   photo.title = data.get('title')
   photo.slug = re.sub(' +', '_', photo.title)
   photo.caption = data.get('caption')
   if (data.get('image') is not None):
     img_file = data.get('image')
     photo.image.save('%s' % (img_file.name), img_file, save=True)
   photo.save()
   galleries = data.get('galleries')
   if galleries is not None:
     for gallery in galleries:
       gallery.photos.add(photo)
       gallery.save()
   return photo