On Wed, 2009-01-14 at 10:42 +0100, Thomas Guettler wrote:
> Hi,
> 
> I read the docs for the sync_db signal:
>    http://docs.djangoproject.com/en/dev/ref/signals/#post-syncdb
> 
> The signal gets fired several times. Since my app has several model classes.


The "since" bit doesn't follow. The post_syncdb signal is only emitted
once by the syncdb management command.
> 
> But how can you know that the tabel for a particular model was just created?

There's a slight oddity in the way the post_syncdb signal is emitted
(it's not a completely silly idea, but it takes some getting used to and
we could have maybe done it differently). It sends all the models that
were created, not matter what application they're in, but it emits the
signal once for each application (setting the "app" and "sender"
parameters to the different application name each time).

However, this does mean you have to check, for each model in the
"created_models" parameter, whether it's a model in the application you
care about or not.

> Or do you need to write the callback method the way, that it can be called
> several times (for example: check if change was already done before
> changing something)

You need to do this if your action doesn't depend on particular models.
The post_syncdb signal is sent for every application in your
INSTALLED_APPS list, regardless of whether or not they were changed.
However, you can tell if some model in the application was affected by
looking to see if it is in the created_models parameter list.

So, if you're writing a post_syncdb handler that doesn't act on
particular models, but does something for the entire application, you
need to check whether you've done it before.

Regards,
Malcolm



--~--~---------~--~----~------------~-------~--~----~
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