I decided to use checking date_join aproach, until I found the simple
and universal way. It is a little hacky but more straightforward.
This is my dispatcher in the models.py of the messaging aplication:
from django.dispatch import dispatcher
from django.db.models import signals
from messaging.views import send_welcome_message
dispatcher.connect(send_welcome_message,
signal=signals.post_save,
sender=User)
And this is the send_welcome_message function:
def send_welcome_message(instance, sender_id=1):
now = datetime.now()
if now - instance.date_joined < timedelta(seconds = 1):
template = get_template('messaging/welcome.txt')
message = template.render(Context({'username':
instance.username}))
m = Message(sender_id = sender_id,
receiver = instance,
message = message)
m.save()
On 15 Ağustos, 12:48, omat <[EMAIL PROTECTED]> wrote:
> Hi,
>
> To send a welcome message to a new user, I am listening for a
> "post_save" signal from an auth.models.User class and it works fine.
> But I need to determine whether the user is newly created.
>
> I can hook to the "pre_save" instead of "post_save" and check for the
> "instance.id". This way I can determine if the user is new but this
> time I do not know the new users id, which I need to register a
> message for her. So with this approach, I need to listen for both
> "pre_save" and "post_save", create a premature message on pre_save and
> update it with the user.id on post_save.
>
> This felt a little dirty. Other way might be checking the
> "date_joined" which looks even dirtier.
>
> Any suggestions?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---