Hi everyone,

I'm running Python 2.6.1, Django Trunk.

I have a model (Entry) with a ManyToMany (Categories). I need to be
able to iterate over these categories whenever my parent model is
saved.

I've tried overriding save_model in the admin, and adding a post_save
signal to Entry in order to be able to iterate over the categories.
The problem only occurs on an insert. If I do:

class Entry(models.Model):
    name = models.CharField(max_length=100)
    categories = models.ManyToManyField(Category)

    class Meta:
        verbose_name_plural = 'Entries'

    def __unicode__(self):
        return self.name

class EntryAdmin(admin.ModelAdmin):
    def save_model(self, request, obj, form, change):
        obj.save()
        print obj.categories.all()

obj.categories.all() = []

However, when performing an update, I have a list of Category objects.
Is this a model lifecycle issue as far as when the ManyToMany gets
saved? What can I do to be able to access the list of categories when
the object is created?

TIA,
Brandon
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to