I am trying to make a combined image of all images added to a modell in django with inline editing and a ForeignKey. Ive got these models (simplified):
class Modell(models.Model):
title = models.CharField('beskrivelse', max_length=200)
slug = models.SlugField()
is_public = models.BooleanField('publisert', default=True)
def __unicode__(self):
return self.title
def save(self, **kwargs):
super(Modell, self).save(**kwargs)
on_modell_saved(self)
class Image(models.Model):
modell = models.ForeignKey(Modell, related_name="images")
image = ThumbnailImageField('bilde', upload_to=get_upload_path_image)
class Meta:
verbose_name = 'bilde'
verbose_name_plural = 'bilder'
def __unicode__(self):
return str(self.image)
Then i add Image to the Modell with AdminInline, so when i save the Modell i save x number of images.
But when I try to do something with Modell.images.all in the on_modell_saved function i cant get hold of the objects. Ive got this function that is executed at Modell.save()
def on_modell_saved(instance):
for img in instance.images.all():
print img
This only prints something the second time i save the Modell and not the first time. So anybody know how to call a function after all items that you are adding with AdminInline is saved?