2

I am working on a workflow to create an order. Here is what I got so far

from django.db import models
from django.utils.translation import ugettext_lazy as _

from django_fsm import FSMField, transition

from ev5.core.models import TimeStampedModel


class Order(TimeStampedModel):
    STATE_CHOICES = (
        ('start', _('Start')),
        ('received', _('Received')),
        ('completed', _('Completed')),
        ('approved', _('Approved')),
    )
    date_order = models.DateTimeField(_('Order date'))
    customer = models.ForeignKey('customers.Customer')
    state = FSMField(...)

    def get_id_display(self):
        return '#{0.8d}'.format(self.pk)

    def __str__(self):
        return _('Order {} ({})').format(self.get_id_display(),
                                         self.get_state_display())

    @transition(field=state, source='start', target='received')
    def received(self):
        pass

    @transition(field=state, source='placed', target='completed')
    def completed(self):
        pass

    @transition(field=state, source='completed', target='approved')
    def approved(self):
        pass

I need to implement a standard workflow with three linear steps, i.e. Select Plan & Preference, Personal Information, and Review & Payment.

Select Plan & Preferences: A client may choose one plan as well as some craft products.

Personal Information: A client will fill fields related to where he lives, phone number, first name, last name, email, ...

Review & Payment : Create an account if necessary, Review his/her order and make the payment related to the current order.

Roughly, an account and an order will be recorded at the end step of the workflow if the payment is accepted (i.e. eCommerce). Hence, during the transition, I don't want the information to be saved in my database. How could I record the information temporarily during the transition? If I can store that information temporarily, how could I save the information in the database once the payment is accepted? Be aware that the payment is the very last step of the workflow.

UPDATE

I don't want to save the user's information, I would put it in the cache. Save the users info dictionary for certain time. The key for the cache could be a buy order, or I can use something from de personal information, I need a key for the cache.

cache.set('user_{}'.format(buy_order), {userdata}, 3600) # one hour

Then, when I save the info, in the last step I can get the dictionary.

user_data = cache.get('user_{}'.format(buy_order))
User.objects.create(**user_data)

I found that solution, but I don't know if it is the best solution. In general, I know it is relevant to keep tracking that information, but I am limited by the budget (i.e. storage, performance, ...) on that project, so I can't do it.

dave
  • 93
  • 2
  • 10

0 Answers0