Mr Dot
Mr Dot

Reputation: 277

How include Recipients to django-postman

in django postmon, when sending a message, an empty recipient field, how to auto-detect the recipient by ID, if the message is sent from the recipient's profile page? thank

Upvotes: 0

Views: 52

Answers (1)

Lars
Lars

Reputation: 1270

You can access user model in views. AND you can do it like :-

views.py

def your_view(request,user_id):
    name = get_object_or_404(User,user_is=user_id)
    model_contains_recipent_field = model_name.objects.get(user=user_id)
    recipent_form = RecipentForm(model_contains_recipent_field=request.POST)

    if request.method == 'POST':
        if recipent_form.is_valid():
            recipent_form.instance.recipent_by = request.user

    context = {'name':name,'model_contains_recipent_field':model_contains_recipent_field,'recipent_form':recipent_form}
    return render(request, 'mains/your_template.html, context)

Note 1 :- You will have to a Recipent Form that i accessed in the view.

Note 2 :- model_contains_recipent_field is the model that contains recipent field.

If you will access recipent_form then it'll select recipient's profile page by user_id .

Upvotes: 1

Related Questions