Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » how create an action in admin for single object? [RSS Feed]

#1 Jan. 21, 2011 13:03:28

Ivo B.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

how create an action in admin for single object?


How can I create an action for an object in the change list?

At the moment, I created an admin action with an intermediate page and I am
only selecting on object, but that is not nice and too complicated for the
workflow.

I thought the way to go would be to put a little form inside the field_list for
each object. That form has the name of the action as the hidden field. I
haven’t tried it yet, but it should work.

Any other ideas which might be less ‘hacky'?

BTW: I want to be able to call the action without going in the change_view
where there is the “view on side” button for example.

Thanks
ivosmime.p7sDescription:S/MIME cryptographic signature

Attachments:
attachment smime.p7s (4.1 KB)

Offline

#2 Jan. 21, 2011 13:10:10

Daniel R.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

how create an action in admin for single object?


On Friday, January 21, 2011 1:03:12 PM UTC, Ivo Brodien wrote:
>
> How can I create an action for an object in the change list?
>
> At the moment, I created an admin action with an intermediate page and I am
> only selecting on object, but that is not nice and too complicated for the
> workflow.
>
> I thought the way to go would be to put a little form inside the field_list
> for each object. That form has the name of the action as the hidden field. I
> haven’t tried it yet, but it should work.
>
> Any other ideas which might be less ‘hacky'?
>
> BTW: I want to be able to call the action without going in the change_view
> where there is the “view on side” button for example.
>
> Thanks
> ivo
>

I usually do this by setting up a method to return an HTML link to a custom
admin page, referencing that in the list_display tuple:

class MyModelAdmin(admin.ModelAdmin):
list_display = ('name', 'action_link')

def action_link(self, obj):
return "<a href='%s'>Do action on this object</a>" %
reverse('action_view', args=(obj.pk,))
action_link.allow_tags = True
--
DR.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#3 Jan. 21, 2011 14:09:47

Ivo B.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

how create an action in admin for single object?


>
> I usually do this by setting up a method to return an HTML link to a custom
> admin page, referencing that in the list_display tuple:
>
> class MyModelAdmin(admin.ModelAdmin):
> list_display = ('name', 'action_link')
>
> def action_link(self, obj):
> return "<a href='%s'>Do action on this object</a>" %
> reverse('action_view', args=(obj.pk,))
> action_link.allow_tags = True

Thanks, this works. My idea did not, since it was nesting a form inside a form
and things got confused.

In your solution, how do you redirect from the view to the admin?

HttpResponseRedirect(request.get_full_path())
and
HttpResponseRedirect(request.META.get(‘HTTP_REFERER’)

both redirect me to the action_view url not the admin page i came from.

Thanks again!smime.p7sDescription:S/MIME cryptographic signature

Attachments:
attachment smime.p7s (4.1 KB)

Offline

#4 Jan. 21, 2011 14:29:25

Ivo B.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

how create an action in admin for single object?


> In your solution, how do you redirect from the view to the admin?
>
> HttpResponseRedirect(request.get_full_path())
> and
> HttpResponseRedirect(request.META.get(‘HTTP_REFERER’)
>
> both redirect me to the action_view url not the admin page i came from.

I see my mistake. the referrer is the page with the form itself. I have to pass
a next field to the form with the original referrer.


--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

  • Root
  • » Django
  • » how create an action in admin for single object? [RSS Feed]

Board footer

Moderator control

Enjoy the 17th of August
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support