I am developing an application where each instance of a Model object
needs to have some state information attached to it, and it needs to
be able to roll back to the previous state.

This is mainly for auditing purposes.

The logic goes like this (take a simple Books model):

class Book(models.Model):
     author = models.CharField(max_length=20)
     title = models.CharField(max_length=20)

Assuming we have 10 books in the system:

1. UserA retrieves BookA and edits the title
2. UserB has to approve UserA's change before the record is updated

The time between 1 and 2 can be any number of minutes - and during
this time, all other users should see the "un-edited" state of BookA,
till the time that the change submitted is approved. If the change is
discarded, BookA never gets updated. There is no "roll back" (yet).

This is the basic problem I am trying to solve - how to store only the
approved changes, so after some searching I came across two different
types of things that I need:

Some sort of model history - with rollback (django-reversion?)
Some sort of model audit - I can roll my own using ContentTypes, but
is there something better?
Some sort of state flag for each record - here I am not sure how to
proceed - should I use something like django-fsm?

But by far the biggest issue I have is how to only display the "valid"
entry to the users of the application?

I thought of creating duplicate rows for each state change, and store
them with a FK to some audit table, then filter all views to only show
the "final" version of each instance.

So for public views:

Book.objects.filter(state=final)

For "approval":

Book.objects.filter(state=pending)

etc - but then I will have multiple rows for each book - I am sure
someone else has solved this problem before so what's the best
practice for this?

Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to