Comments (3)
I don't mind tweaking this so long as we don't break existing functionality.
Here's the lifecycle:
- User views the preview:
GET
->200
- Use performs the rollback
POST
->302
At what point is your 302
redirect given? Is is before the preview, or after the rollback?
from django-reversion.
Sorry, my bad. Fixed it a few days ago. But here’s some context and the solution. No need for changes from your side.
# models.py
class Media:
class TypeChoices:
PHOTO = 'PH', 'photo'
VIDEO = 'VI', 'video'
proxy_map = {
TypeChoices.PHOTO: "Photo",
TypeChoices.VIDEO: "Video",
}
type = fields.CharField(choices=TypeChoices.choices, max_length=20, db_index=True)
file = fields.FileField(...)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._cast_to_proxy()
def get_edit_url(self):
# Build a dynamic edit url here
return "the-url"
def _cast_to_proxy(self):
if not self.type:
return
proxy_model_name = self.proxy_map.get(self.type, None)
if not proxy_model_name:
return
proxy_model = apps.get_model(self._meta.app_label, proxy_model_name)
self.__class__ = proxy_model
class Photo(Media):
class Meta:
proxy = True
class Video(Media):
class Meta:
proxy = True
# admin.py
class MediaAdmin:
def render_change_form(
self, request, context, add=False, change=False, form_url="", obj=None
):
"""
In some cases, an admin is only registered e.g. to provide auto complete,
but editing is done through proxy models (and their admin classes).
"""
# Revert is set when restoring object through the model admin.
# When the revert flag is set, don't mess around with the redirects.
revert = context.get("revert", False) # => This is how I fixed it.
if obj is not None and revert is False:
# Without the revert check, this would cause an exception, because reversion expects a 20x, not a redirect (30x)
edit_url = obj.get_edit_url()
if not request.path.startswith(edit_url):
return HttpResponseRedirect(
f"{obj.get_edit_url()}?{request.GET.urlencode()}"
)
return super().render_change_form(request, context, add, change, form_url, obj)
from django-reversion.
Thanks for the context! Glad you sorted it yourself!
from django-reversion.
Related Issues (20)
- Django-reversion is incompatible with Wagtail HOT 2
- createinitialrevision fails with iterator error (reversion 4.0.2, Django 3.2) HOT 1
- Re-add support for `bulk_create` HOT 2
- Explain how to create revisions with bulk actions HOT 1
- Add step to show version data and allow for confirmation prior to to reversion HOT 4
- Manytomany Field not deleted or recreate HOT 2
- Using fixtures to initialise versioned inline data HOT 3
- "Could not load - incompatible version data" for versions having an empty PartialDateField HOT 1
- Decorator: create_revision request parameter is inheriting wrong object HOT 1
- Browsing history entries in admin fires pre/post save signals potentially leading to nasty side effects HOT 5
- [enhancement] Storing serialized_data in a JSONField instead of a TextField? HOT 3
- Django 4.2 with VersionAdmin: wrapping in tuples does not have any effect (each field on separate line) HOT 1
- Admin: 'GET' on a change_view creates a transaction block HOT 1
- following OnetoOneField HOT 1
- Using reversion with async on python 3.8 HOT 2
- AttributeError: 'HttpResponseRedirect' object has no attribute 'render' HOT 4
- Allow displaying "non-recoverable" objects as read-only HOT 1
- #951 BUG SELECT DISTINCT ON expressions must match initial ORDER BY HOT 1
- i was looking for a way to add reversions for changes via DRF HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-reversion.