Adding Button in admin form

346 views
Skip to first unread message

Madhu

unread,
Aug 17, 2012, 2:44:51 AM8/17/12
to django...@googlegroups.com
Hello,

I want to add the button along with field in admin form.

ex. Field name "URL" with the "Choose Page" button.
If admin clicks on "Choose Page" button then some list from the database table will be display and admin select any one from that list.

Can anybody help me to add the button in admin form?

Thanks,
Madhu

Thomas Orozco

unread,
Aug 17, 2012, 3:21:35 AM8/17/12
to django...@googlegroups.com

If you're using a ForeignKey for this field, you'll get this behavior by default in the Django admin.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/wSJXqEJkYzoJ.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Madhu

unread,
Aug 17, 2012, 3:41:05 AM8/17/12
to django...@googlegroups.com
Thanks for the replay.

Using foreign key it creates dropdown list, but i want the URL as the character field and "Choose Page" button which having the function which retrieves the database query list.

Thomas Orozco

unread,
Aug 17, 2012, 3:47:02 AM8/17/12
to django...@googlegroups.com

Oh, yeah, sorry about that, it's an admin parameter that you must use, can't recall the exact name, but it's something like id only.

To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/gsOd9uZzCUgJ.

Thomas Orozco

unread,
Aug 17, 2012, 3:49:24 AM8/17/12
to django...@googlegroups.com

It's raw_id_fields! (see the docs for more detail : ) )

On your modeladmin, set that to a list including the name (as string) of your field, and you should have what you want.

Let me know if I misunderstood.

Amyth Arora

unread,
Aug 17, 2012, 3:58:42 AM8/17/12
to django...@googlegroups.com
Change the ModelField to type "CharField" and you should have a input
box in the admin.
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/wSJXqEJkYzoJ.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.



--
Best Regards,

Amyth Arora
+919999856363
+918800212140

Thomas Orozco

unread,
Aug 17, 2012, 4:04:12 AM8/17/12
to django...@googlegroups.com

I might be off, but I believe that they want to get a list of objects from the database, a ForeignKey seems more appropriate here, or am I missing something?

Madhu

unread,
Aug 17, 2012, 5:26:42 AM8/17/12
to django...@googlegroups.com
Can you please tell me how to add the Buttom on admin form in django?
I want to add the button beside the field.

Amyth Arora

unread,
Aug 17, 2012, 5:28:55 AM8/17/12
to django...@googlegroups.com
Django Admin by default only provides Dropdown option for Foreign Keys.

On Fri, Aug 17, 2012 at 2:56 PM, Madhu <madhush...@gmail.com> wrote:
> Can you please tell me how to add the Buttom on admin form in django?
> I want to add the button beside the field.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/WACTMw1ykxMJ.
>
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.



--
Thanks & Regards
----------------------------

Amyth [Admin - Techstricks]
Email - aroras....@gmail.com, ad...@techstricks.com
Twitter - @a_myth_________
http://techstricks.com/

Thomas Orozco

unread,
Aug 17, 2012, 5:38:08 AM8/17/12
to django...@googlegroups.com

(again) did you try using raw_id_fields?

Le 17 août 2012 11:26, "Madhu" <madhush...@gmail.com> a écrit :
Can you please tell me how to add the Buttom on admin form in django?
I want to add the button beside the field.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/WACTMw1ykxMJ.

Madhu

unread,
Aug 17, 2012, 6:01:50 AM8/17/12
to django...@googlegroups.com

I try the row_id_fields, but its not helpful for me.
I want the button will be display in admin form.
Using row_id_fields its just the linking of foreign key i don't want that.
The button functionality will be later before that i want the button tag will be display on admin form.

Thomas Orozco

unread,
Aug 17, 2012, 6:05:08 AM8/17/12
to django...@googlegroups.com

Then there must be something I don't understand in what you need, could you describe a bit more?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/7CrtkDOzAycJ.

Madhu

unread,
Aug 17, 2012, 6:15:08 AM8/17/12
to django...@googlegroups.com
Ok. I will explain it in brief.

I want the button like the image field having the Browse button with the Image field in admin side i want the same button but the functionality may be different. Don't want that the browser button functionality but i want the button along with the my URL character field.
That button should be be display and we i click on that button then some functionality.

Right now i didn't understand, how to add that button in admin form.
Can you please suggest?

Thomas Orozco

unread,
Aug 17, 2012, 6:31:45 AM8/17/12
to django...@googlegroups.com

So you would want to have a link to the url that was entered?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/Ov0QyqEbsCQJ.

Madhu

unread,
Aug 17, 2012, 6:42:01 AM8/17/12
to django...@googlegroups.com
No. URL linking is not the problem. I have the problem to add the input button in admin form.

There will be so many buttons in admin form like save, add, delete. I want to add my own button, but in the middle of admin form not at the submit line or upper part of the admin form. That button should be display near to my character field.

Using html we create <input type=button> then button tag will be display in the html page.
I want the same input button on the admin form.

Thomas Orozco

unread,
Aug 17, 2012, 6:44:37 AM8/17/12
to django...@googlegroups.com

I'm sorry, I really have a hard time understanding what you need, but you might want to try overriding the form template to add your button?

If so, try the change_form_template parameter.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/LVBJArH-RH8J.

Jani Tiainen

unread,
Aug 17, 2012, 6:48:09 AM8/17/12
to django...@googlegroups.com
If I understood correctly OP want's to display button after URL field
that says something like "select existing". When user clicks it it
fetches (ajax query maybe) list of URLs from database and user can
select value that is then copied to text field instead of typing URL
manually to text field.

How to achieve that kind of functionality in admin beats me. Probably it
would be possible with custom field though I think it might work better
out with totally custom form that looks like admin page where it's very
easy to add more control than standard admin does.

--
Jani Tiainen

- Well planned is half done and a half done has been sufficient before...

Madhu

unread,
Aug 17, 2012, 7:05:07 AM8/17/12
to django...@googlegroups.com
Yes, That's right. I tried to change the admin form, but the button is not added.
the fuctionality Jani Tiainen said i want the same fuctionality, but the now first problem is adding button in change form.

Alexis Roda

unread,
Aug 17, 2012, 8:00:58 AM8/17/12
to django...@googlegroups.com
Al 17/08/12 13:05, En/na Madhu ha escrit:
As Jani has pointed I think that a custom widget (text field + button)
plus a custom form that associates that widget to the 'url' field could
do the trick.


HTH
Reply all
Reply to author
Forward
0 new messages