{"id":15907957,"url":"https://github.com/dennybiasiolli/django-reversion-rest-framework","last_synced_at":"2025-03-21T21:31:48.986Z","repository":{"id":44575265,"uuid":"390344112","full_name":"dennybiasiolli/django-reversion-rest-framework","owner":"dennybiasiolli","description":"A package for adding a django-reversion history endpoint to django-rest-framework ModelViewSet.","archived":false,"fork":false,"pushed_at":"2024-04-26T06:45:54.000Z","size":202,"stargazers_count":10,"open_issues_count":3,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-05-01T15:32:29.240Z","etag":null,"topics":["django","django-rest-framework","django-reversion","hacktoberfest","python","rest","rest-api"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/django-reversion-rest-framework/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dennybiasiolli.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-07-28T12:29:32.000Z","updated_at":"2024-05-06T03:27:20.118Z","dependencies_parsed_at":"2023-10-23T16:35:06.280Z","dependency_job_id":"bd0385f9-cfa8-418c-bc09-65bc3ce5558b","html_url":"https://github.com/dennybiasiolli/django-reversion-rest-framework","commit_stats":{"total_commits":95,"total_committers":6,"mean_commits":"15.833333333333334","dds":0.6421052631578947,"last_synced_commit":"fc5c8c6821a5654666602ff01e43dc39a646e8fd"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dennybiasiolli%2Fdjango-reversion-rest-framework","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dennybiasiolli%2Fdjango-reversion-rest-framework/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dennybiasiolli%2Fdjango-reversion-rest-framework/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dennybiasiolli%2Fdjango-reversion-rest-framework/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dennybiasiolli","download_url":"https://codeload.github.com/dennybiasiolli/django-reversion-rest-framework/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244874377,"owners_count":20524577,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["django","django-rest-framework","django-reversion","hacktoberfest","python","rest","rest-api"],"created_at":"2024-10-06T14:07:35.773Z","updated_at":"2025-03-21T21:31:48.975Z","avatar_url":"https://github.com/dennybiasiolli.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# django-reversion-rest-framework\n\nA package for adding a django-reversion history endpoint to django-rest-framework ModelViewSet.\n\n\n## Configuration\n\nFollow the official website for the installation and the integration of django-reversion in your project, otherwise future steps won't work.\n\nYou might need to enable the `ReversionMiddleware` for storing a version for each API change.\u003cbr\u003e\nFollow the instructions [here](https://django-reversion.readthedocs.io/en/stable/middleware.html),\nyou should add `'reversion.middleware.RevisionMiddleware'` to your `MIDDLEWARE` setting.\n\n\n### Using the HistoryModelViewSet\n\nThe `HistoryModelViewSet` extends django-rest-framework's `ModelViewSet` adding\n\n- a GET `history` action in the detail (`/my-model-url/\u003cpk\u003e/history/`)\n\n    displaying a list of all revisions of that specific record\n\n- a GET `version` action in the history detail (`/my-model-url/\u003cpk\u003e/history/\u003cversion_pk\u003e/`)\n\n    displaying a specific revisions of that specific record\n\n- a GET `deleted` action in the list (`/my-model-url/deleted/`)\n\n    displaying a list of all deleted records\n\n- a POST `revert` action in the detail (`/my-model-url/\u003cpk\u003e/revert/\u003cversion_pk\u003e/`)\n\n    allowing users to revert to a previous revision of the object\n\nYou can use the `HistoryModelViewSet` in place of the `ModelViewSet`\nduring viewsets definition.\n\n```py\nfrom reversion_rest_framework.viewsets import HistoryModelViewSet\n\n\nclass MyModelViewSet(HistoryModelViewSet):\n    # ...\n```\n\nFor advanced or selective implementation, you can use `reversion_rest_framework.mixins`.\n\n- `HistoryMixin` contains `history` and `version` actions\n\n- `DeletedMixin` contains only the `deleted` action\n\n- `RevertMixin` contains `history`, `version` and `revert` actions\n\n\n### Customizing the VersionSerializer\n\nThe `HistoryModelViewSet` comes up with actions using a `VersionSerializer`.\u003cbr\u003e\nTo customize the serializer with one of your own, you can use `version_serializer`.\u003cbr\u003e\nFor example, if you want to customize the `user` serializer inside a revision,\nyou can use the following code:\n\n```py\nfrom django.contrib.auth.models import User\nfrom rest_framework import serializers\nfrom reversion.models import Revision, Version\nfrom reversion_rest_framework.serializers import (\n    RevisionSerializer,\n    VersionSerializer,\n)\nfrom reversion_rest_framework.viewsets import HistoryModelViewSet\n\n\nclass UserSerializer(serializers.ModelSerializer):\n    class Meta:\n        model = User\n        fields = [\"id\", \"username\"]\n\n\nclass CustomRevisionSerializer(RevisionSerializer):\n    user = UserSerializer()\n\n\nclass CustomVersionSerializer(VersionSerializer):\n    revision = CustomRevisionSerializer()\n\n\nclass MyModelViewSet(HistoryModelViewSet):\n    version_serializer = CustomVersionSerializer\n    # ...\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdennybiasiolli%2Fdjango-reversion-rest-framework","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdennybiasiolli%2Fdjango-reversion-rest-framework","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdennybiasiolli%2Fdjango-reversion-rest-framework/lists"}