title: is there a way to convert a view function to a celery task?
body: <p>task.py</p>
  
  <pre><code>@task(name="send_mail_to_custormer")
  def order_created(order_id):
      order = Order.objects.get(id=order_id)
      subject = 'Order nr. {}'.format(order.id)
      message = 'Dear {} {},\n\nYou have successfully placed an order. Your order id is {}'.format(order.first_name,
                                                          order.last_name, order.id)
      from_email = settings.EMAIL_HOST_USER
      to_email = [order.email]
      mail_sent = send_mail(
                              subject,
                              message,
                              from_email,
                              to_email,
                              fail_silently=False
                            )
      return mail_sent
  </code></pre>
  
  <p>views.py</p>
  
  <pre><code>def order_create(request):
  cart = Cart(request)
  if request.method == 'POST':
      form = OrderCreateForm(request.POST)
      if form.is_valid():
          order = form.save()
          for item in cart:
              try:
                  OrderItem.objects.create(order=order,
                                           product=item['product'],
                                           price=item['price'],
                                           quantity=item['quantity'])
              except:
                  pass
              cart.clear()
              order_created.delay(order.id)
          return render(request,'orders/order_created.html', {'cart': cart, 'order': order})
  else:
      form = OrderCreateForm()
  return render(request, 'orders/order_create.html', {'cart': cart, 'form': form})
  </code></pre>
  
  <p>cart.py</p>
  
  <pre><code>class Cart(object):
  
  def __init__(self, request):
      self.session = request.session
      cart = self.session.get(settings.CART_SESSION_ID)
      if not cart:
          cart = self.session[settings.CART_SESSION_ID] = {}
      self.cart = cart
  
  def add(self, product, quantity=1, update_quantity=False):
      product_id = str(product.id)
      if product_id not in self.cart:
          self.cart[product_id] = {'quantity': 0,
                                   'price': str(product.price)}
      if update_quantity:
          self.cart[product_id]['quantity'] = quantity
      else:
          self.cart[product_id]['quantity'] += quantity
      self.save()
  
  def save(self):
      self.session[settings.CART_SESSION_ID] = self.cart
      self.session.modified = True
  </code></pre>
  
  <p>Now the celery task sends mail and view function creates order after taking values from cart and order form. How I can change the task to create order? Is it a good practice doing so. Hope somebody can help me, thank you. Also is it possible to do a success message using django message framework as celery task?</p>