How to "Undo" in two different Django views

40 views
Skip to first unread message

weihsi...@gmail.com

unread,
Aug 8, 2016, 6:34:12 AM8/8/16
to django-reversion discussion group
Hello all,

I would like to "undo" the latest action from my Django application and I've read the document but I still have no idea how to do. Can anyone give me an example? Many thanks.

Here is my current code:

def opponent_shooting(request, team_id, game_id):

    isMade_opponent = request.COOKIES["OppoMade"]

    hotzone_id_opponent = request.COOKIES["OppoHotZone"]


    game = Game.objects.get(pk=game_id)

    team = Team.objects.get(pk=team_id)


    with reversion.create_revision():

        oppo_obj = OpponentHotZone(game=game, opponent=game.opponent,team=team, zone=hotzone_id_opponent)

        if isMade_opponent == "Y":

            oppo_obj.isMade = True

        else:

            oppo_obj.isMade = False


        oppo_obj.save()


        # Store some meta-information.

        reversion.set_user(request.user)


    return redirect('playball', team_id=team_id, game_id=game_id)


def undo_opponent_shooting(request, team_id, game_id):

    revision = Revision.objects.filter(user_id=request.user.id).order_by("-date_created")[0]

    versions = Version.objects.get_for_object(revision)

    revision.revert(delete=True)

    return redirect('playball', team_id=team_id, game_id=game_id)

Dave Hall

unread,
Aug 9, 2016, 5:27:10 AM8/9/16
to django-reversion discussion group
I don't thing that django-reversion is suitable for this use-case. To revert the last action, you simply need to delete the last OpponentHotZone model you created. It'll probably be much simpler to do that directly.

--
You received this message because you are subscribed to the Google Groups "django-reversion discussion group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-reversi...@googlegroups.com.
To post to this group, send email to django-r...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-reversion.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages