Search code examples
djangogoogle-app-enginedjango-nonrel

sending invitation to online users in django


I am using http://mpcabd.igeex.biz/get-online-users-in-django/ to successfully get the list of online users. I am attaching checkboxes along with usernames while displaying in template. Is this possible any online user (lets say 'A') should select checkboxes of list of online users and send invitation to selected group of people ? I am doing this because I want to make group of users who accepted the invitation initiated by user 'A'. If yes,then how should I go ahead ?

Update: Just forgot to add that users will receive the notification the way StackExchange shows its in upper left corner of this website. How to do this also ?


Solution

  • Umm, at the end of that tutorial, you have access to a python list of user models and their usernames / ids.

    At a basic level, something like...

    <form method="post">
    {% for user in users %}
        <ul>
            <li><input type="checkbox" name="selected_users" value="{{ user.id }}"/> 
                 {{ user.username }}</li>
        </ul>
    {% endfor %}
    <input type="submit" value="send emails" />
    </form>
    

    class UserMessage(models.Model):
         user = models.ForeignKey(User)
         message = models.TextField()
    

    users = User.objects.filter(id__in=request.POST.getlist('selected_users'))
    for user in users:
        user.usermessage_set.create(message="Hello you've been invited")
    

    Now just display user.usermessage_set.all() or a limited subset for your stackoverflow like inbox (probably best via ajax).