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

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.

Related

Can I access my website from Django admin panel?

I am trying to develop a website where I can see the homepage as it is from Django admin panel. The reason I want that is I want to edit the name of the static content like 'Home' to 'All' along with the change of slide show picture. In summary, I want to change the website layout from Django admin panel that is not accessible to users. Is that possible? I just want an idea of how to implement the process.
Static texts you can change in admin panel with different modules:
for example django-rosetta or my own library Django-tof. https://github.com/wP-soft-GmbH/django-tof
But in your case, i think, you want to made something more.
For this case you can use django-flat-pages, already included in Django, if you have a static web-page.
you can edit every element on the page and after save, you can see it on the front.
if you really want to change the django templates, which you use in your views, you can create a simple template editor in the admin panel based on a widget like django-Ckeditor.

How to add button in django admin site?

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.

How to use django raw_id_fields in a view?

I am making a view, to make some POST requests on my Django server. I need a way to select something and the proper widget that I need for the same is Django admin panel's raw_id_fields.
Widget:
Popup:
I was looking for a jquery plugin to do the same, but couldn't find anything. Is there a plugin / widget to have this functionality in my own views.
Is there a way to use this exact widget in my views.
I found django-yaac whose README says that I can use this outside the admin. However I can't seem to figure out how to use this outside the admin.
I'm not sure if this helps you, but anywhere in your template you can access a model's id like this:
{{ myModelObject.id }}
You can use it in a hidden field or javascript variable, and then you can manipulate it however you like.

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.

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.