Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
django-reversion-rest-framework
Advanced tools
A package for adding a django-reversion history endpoint to django-rest-framework ModelViewSet
A package for adding a django-reversion history endpoint to django-rest-framework ModelViewSet.
Follow the official website for the installation and the integration of django-reversion in your project, otherwise future steps won't work.
You might need to enable the ReversionMiddleware
for storing a version for each API change.
Follow the instructions here,
you should add 'reversion.middleware.RevisionMiddleware'
to your MIDDLEWARE
setting.
The HistoryModelViewSet
extends django-rest-framework's ModelViewSet
adding
a GET history
action in the detail (/my-model-url/<pk>/history/
)
displaying a list of all revisions of that specific record
a GET version
action in the history detail (/my-model-url/<pk>/history/<version_pk>/
)
displaying a specific revisions of that specific record
a GET deleted
action in the list (/my-model-url/deleted/
)
displaying a list of all deleted records
a POST revert
action in the detail (/my-model-url/<pk>/revert/<version_pk>/
)
allowing users to revert to a previous revision of the object
You can use the HistoryModelViewSet
in place of the ModelViewSet
during viewsets definition.
from reversion_rest_framework.viewsets import HistoryModelViewSet
class MyModelViewSet(HistoryModelViewSet):
# ...
For advanced or selective implementation, you can use reversion_rest_framework.mixins
.
HistoryMixin
contains history
and version
actions
DeletedMixin
contains only the deleted
action
ReadOnlyMixin
contains history
, version
and deleted
actions
RevertMixin
contains history
, version
and revert
actions
The HistoryModelViewSet
comes up with actions using a VersionSerializer
.
To customize the serializer with one of your own, you can use version_serializer
.
For example, if you want to customize the user
serializer inside a revision,
you can use the following code:
from django.contrib.auth.models import User
from rest_framework import serializers
from reversion.models import Revision, Version
from reversion_rest_framework.serializers import (
RevisionSerializer,
VersionSerializer,
)
from reversion_rest_framework.viewsets import HistoryModelViewSet
class UserSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = ["id", "username"]
class CustomRevisionSerializer(RevisionSerializer):
user = UserSerializer()
class CustomVersionSerializer(VersionSerializer):
revision = CustomRevisionSerializer()
class MyModelViewSet(HistoryModelViewSet):
version_serializer = CustomVersionSerializer
# ...
FAQs
A package for adding a django-reversion history endpoint to django-rest-framework ModelViewSet
We found that django-reversion-rest-framework demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.