-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NoReverseMatch when "save_as = True" enabled #60
Comments
I'm not positive this is your issue, but I think you need
|
No. That's not it. When pasted, I actually removed the extra actions (and mistakenly the trailing comma) for simplicity. I'll try to recreate a simple app from scratch and see if produces the error and keep it posted here. Thx @AlexRiina |
I'm thinking there's some inconsistency between detecting if it's an "add" or "change" form. What version of Django? |
@AlexRiina I've created a simple app here which also producing the same error. @crccheck I'm using the dev version - |
Would you consider the below change on def get_change_actions(self, request, object_id, form_url):
"""
Override this to customize what actions get to the change view.
This takes the same parameters as `change_view`.
For example, to restrict actions to superusers, you could do:
class ChoiceAdmin(DjangoObjectActions, admin.ModelAdmin):
def get_change_actions(self, request, **kwargs):
if request.user.is_superuser:
return super(ChoiceAdmin, self).get_change_actions(
request, **kwargs
)
return []
"""
# if the request from 'Save as new' button
if '_saveasnew' in request.POST:
return []
return self.change_actions |
The issue is basically that "save as new" is an add option that takes place from the change_form template. When there is an error saving as new (in this case a duplicate value on a unique field), the error is rendered on the change_form template, but there is no object_id like we might expect. Django avoids this crash with the history button by saving the url as a variable which seems to set it to an empty string in an error case, so the history button leads to the relative path Unfortunately, django passes the original The similar handling in django's
|
@crccheck / @AlexRiina , Is there any update on this? I'm currently using my dirty fix, but hoping to see @AlexRiina's proposal be implemented. |
I haven't had any free time so far, hopefully by this weekend. I'm also looking for a regression test, on #61 or on its own is ok too. update: oops that PR is for an unrelated issue |
I threw With diff --git a/example_project/polls/admin.py b/example_project/polls/admin.py
index 4f11017..d7bfec7 100644
--- a/example_project/polls/admin.py
+++ b/example_project/polls/admin.py
@@ -14,6 +14,7 @@ from .models import Choice, Poll, Comment
class ChoiceAdmin(DjangoObjectActions, admin.ModelAdmin):
list_display = ('poll', 'choice_text', 'votes')
+ save_as = True
# Actions
######### |
With an admin model
I'm getting following error when I click
Save as new
button (highlighting line # 7).The text was updated successfully, but these errors were encountered: