Weird, I dont see our conversation,

Anyway here is a simple setup:

urls.py:

from django.conf.urls import url

from .views import ajax_comment_send

urlpatterns = [

 url("comment_send", ajax_comment_send, name="comment_send"),

]



then a view - this is from my project, you will to make changes to do the 
calculations. :)

...

def ajax_comment_send(request):
 if not request.is_ajax():
 return HttpResponse('SERVER RESPONSE: ajax_comment_send, Not an ajax call.'
)

 comment_thread = None
 recipient = None

 if request.method == "POST":
 content = request.POST.get("content", "0")
 recip_id_str = request.POST.get("recip_id", "0") # this is where to make 
changes

 if scope == 'story':
 comment_thread = CommentThread.objects.get(story__id=int(recip_id_str))
 recipient = get_object_or_404(User, pk=comment_thread.first_recipient_id)

...

 send_message = Comment.objects.create(
 body=content,
 comment_thread=comment_thread,
 recipient=recipient,
 sender=request.user
 )

 send_message.save()

 return HttpResponse("SERVER RESPONSE ajax_comment_send; send_message.id: " 
+
 str(send_message.id)) # this is a check to help with debugging

 return HttpResponse('SERVER RESPONSE: ajax_comment_send, AJAX fell 
through.')




this is the key part ; javascript in the front end:


function replyThread (scope, recip_id, cntnt) {
 console.log('replyThread : scope:' + scope + ', recip_id: ' + recip_id + ', 
content: ' + cntnt);
 $.ajax({
 type: 'POST',
 url: '/jos_comments/comment_send',
 data: { // this is the part that scoops up the agents and sends it to the 
backend
 'scope': scope, // This is unique to me
 'recip_id': recip_id,
 'content': cntnt
 },
 success: function (serverResponse_data) {
 console.log('replyThread success: ' + serverResponse_data);
 $('#message_box').html(
 "<div class='center head_1' style='" +
 "color: #9bcd69; width: 100%; height: 100%;'>Message sent!</div>");
 setTimeout(function () {
 getThreadComments(serverResponse_data.split(':')[1]); // this reloads the 
messages; you probably don't need
 }, 1500);
 },
 error: function (serverResponse_data) {
 console.log('error:' + JSON.stringify(serverResponse_data).split(',').join(
'\n')); // helps with debug
 }
 });
}

Hope this helps










On Saturday, November 4, 2017 at 8:27:12 PM UTC-7, Jack wrote:
>
> I have a model called *Team*, which has a ForeignKey relationship with 
> *User* (a team can have many users, but a user can only be part of one 
> team).
>
> A user can create a team, and that user will automatically become a *Team 
> Leader* (a group, not a model).  The team leader can query the database 
> for other users and send invitations to other users join his team.  Users 
> who receive an invitation can either accept or decline the invitation; if a 
> user accepts an invitation, he joins the team as as a *Team Member*
>
> My question is, how do I go about designing the invitation system?  After 
> the team leader clicks the 'Send Invitation' button, the receiving-user 
> should see a special invitation message on his dashboard, which he can 
> either accept or decline.
>
> My current thinking tells me I should create a model called *Invitation* 
> which has a OneToOne relationship with User.  When an invitation is sent, 
> an instance of Invitation is created which is assigned to the 
> receiving-user.  The invitation instance will be deleted when the 
> receiving-user accepts or declines the invitation.
>
> Another method I can think of is to send an Email to the receiving-user.  
> The Email will be like an account activation Email, except the activation 
> link adds the receiving-user to the team and marks the receiving-user as a 
> *team 
> member.*
>
> Pointers and guidance welcome.  I feel like both my methods are clumsy and 
> maybe there is a built-in feature in Django which I missed which could 
> solve this problem much easier.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7a15cf74-98d1-40ca-8a8a-e73f09e5cb5c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to