Save object data in list and use in parameter

I need to use the object details of obj to save in a list or some sort to use as a parameter in my send_order_verification() function.

def order(request):
    if request.method == 'POST':
        form = OrderForm(request.POST)
        if form.is_valid():
            obj = form
            obj.save()

            send_order_verification(order_details, obj.email)

This is my send_order_verification() function:

def send_order_verification(order_details, email):
    return send_mail(
                    ('Thank you for your order #{0}', x),
                    ('Name: {0}\nEmail: {1}\nTelephone: {2}', x, y, z),
                     [settings.EMAIL_SEND_TO],
                     ['{0}' % email]
                     )

How could this be done? I tried with order_details = [obj.name, obj.email, obj.telephone] but can't access it with order_details[0] and so forth.

1 answer

  • answered 2018-03-13 21:28 Walucas

    Send the object itself:

    def order(request):
        if request.method == 'POST':
            form = OrderForm(request.POST)
            if form.is_valid():
                obj = form
                obj.save()
    
                send_order_verification(obj)
    
    def send_order_verification(order_details):
        return send_mail(
                        ('Thank you for your order #{0}', order_details.name),
                        ('Name: {0}\nEmail: {1}\nTelephone: {2}', order_details.name, order_details.email, order_details.telefone),
                         [settings.EMAIL_SEND_TO],
                         ['{0}' % order_details.email]
                         )