ORM) from django.db import transaction with transaction.atomic(): user = User.objects.create(...) user.profile.update(...) user.profile.save() SOME EXAMPLES…
time() - timer.start print("started {}s ago".format(t)) sleep(2) # within the Timed class def __enter__(self): self.start = time() return self SUPPORT FOR as
to use # this as a decorator, too! class bettertimed(ContextDecorator): def __enter__(self): self.start = time() return self def __exit__(self, type, value, traceback): self.end = time() total = self.end - self.start THE CONTEXT DECORATOR CLASS