How to add button in django admin site? - django

I do want to know how to add button in django admin site.I tried many stuff but I couldn't able to do the stuff.I want to add a reset button for an attribute in the model where it should regenerate the value for the attribute.

You're going to have to edit the admin files to add this button, it may be easier to inject a piece of JavaScript code and a button into the admin template to reset the form fields.

Related

Enable editing a field in Django admin's list view

Consider a model that stores application forms. I would like to use Django admin to quickly view applications and change their status. I would like to be able to change the status of an application right in the view listing all the applications without having to open each application for editing. So, is it possible to make a field editable right in the admin list view?

django admin panel add a confirmation window

I need to add a confirmation window on admin change model submit "save". Smth like this: "Do you really want to apply changes? Yes/No". I need it only for one model and only if the changed model satisfy the other conditions. I can`t override django template for one model cause of using django-admin-tool. How can i do this ?

Add app model in new Page by drop-down select in Django

It is bit complicated so I hope that explain this properly.
I have app which is created within new Page in admin site. In that app I have also drop-down list with my installed apps like on picture.
drop-down of installed apps in new Page
I need someway to add models of selected app dynamicaly by add button at the end of this Page. So if I select app, with add button add model of app below page content, next select second app and add model below app added before. So at the end I will have filled Page with models of apps that I added.
Adding functionality like on this picture or with some add button or add button next to drop-down.
desired functionality
I dont have so much experiences in Django that I can make it self right now. I know that this is possible but I need help of you that you are Django Pro. I really need to make this done.

django admin: Adding a textarea and a button that invokes a function

On the main admin screen I want a link that when clicked would bring up a page with a textarea along with a button that when clicked will invoke a python function. That function would return data that would be displayed on the page below the textarea.
If this were a regular page that was part of my app I could easily do this, but I'm not sure how to integrate something like this into my admin page. Everything thing in admin seems to be tied to a model, and this is not. Do I have to create a dummy model for this? Let's say I do create a dummy model, then how do I get django to display my custom template for this?
Can anyone help with this?
You can use this django app: https://github.com/jsocol/django-adminplus to add links at the bottom of the list of models without adding a dummy once.

replace Add with Get on django admin site

I have a model that I don't want user to manually add/delete objects. Instead, I want to have some Get button that once clicked, it executes some code and automatically update the database.
I was able to do similar things via adding my own admin action. However, adding an admin action by default means you have to have at least one object for your model, you select that object and performs some action.
I want be able to perform my customized action on an empty model (if I can replace the Add button with a Get button on the index page, it will be perfect). Is there a way to do so? thanks!
You could override the add_view method of the django admin model and do whatever you felt like having that view do if you wanted. Poke around through the ModelAdmin code and you can see what it does by default
you could also take a look at this project: https://github.com/imtapps/django-admin-ext and see an example of how to register your own urls for an admin... so you could make your view something like admin/myproject/myapp/model/get and have it do what you'd like...
You can prevent users from adding new objects by removing the "Can add ModelName" permission from that user. If they're a superuser that won't actually stop them from doing that, however.
Admin actions are designed to be run on specific instances of the model; if that's not what your code is doing you probably shouldn't go that particular route. You can override the admin template for your model and add a new button or link to your custom view. You could also remove the Add button entirely by eliminating it from your template, but I'd recommend using permissions instead.