Use the pre_save signal.

Write something like the following into some models.py file:

from django.dispatch import dispatcher
def attach_user_to_object(sender, instance, signal, *args, **kwargs):
    # sender - the model which instance is being saved
    # instance - the instance being saved
    # ... assign the user to the instance if it has the created_by field ...
dispatcher.connect(attach_user_to_object, signal=signals.pre_save)

Regards,
Aidas Bendoraitis




On 7/11/07, Norjee <[EMAIL PROTECTED]> wrote:
>
> Use the events framework. I'm sure there is a pre-save event. Use it
> to execute one (DRY) method  and attach it to all your models.
>
> I personally would just write a custom method (your custom
> attach_user_to_model), which I'd call in all the save methods of the
> models.. But I guess attaching evenents might make you feel more dry.
> On the other hand, is writing rather obscure code really better than
> adding the followin code to your models:
> --------------
> def save(self):
>   attach_user_to_model(self)
> ---------------
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to