Wednesday, January 30, 2013

previous values of custom method in save

Dear friends,

here is the relevant part of my model:

    class Album(models.Model):
        name = models.CharField(max_length=64, blank=True)
        tags = models.ManyToManyField(Tag, blank=True)
        def tags_(self):
            return ', '.join([t.name for t in self.tags.all()])
        def save(self, *args, **kwargs):
            super(Album, self).save(*args, **kwargs)
            json.dump( {'name': self.name, 'tags': self.tags_()} , open('/tmp/info.txt', 'wb'), sort_keys=True)

When I change 'tags' in admin panel and save my model, old tags are being written to file 'info.txt' instead of new ones, but it works good with regular fields like self.name. 
How do I overcome this issue?
Thank you in advance for any advice.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment