I have followed this article on "How to Add Custom Action Buttons to Django Admin" https://medium.com/#hakibenita/how-to-add-custom-action-buttons-to-django-admin-8d266f5b0d41 and I have it almost working. I would like display fields that are pre-populated with values from my model.
Here is what I have so far.
From this page the user can click on the 'Approve' or 'Deny' buttons.
The deny form is simple and looks like this:
Here the user needs to type in a reason for denying and then can click the Submit button to execute custom code to process the denial.
If the user clicks Approve I would like the user to have the ability to adjust some of the values in my Command model so I need to display those values in the form. So the form would look much like the standard django admin Change form but with just a Submit button that when clicked would update the model with user's changes and call my custom code to process the approval. So the Approval form would look something like this:
But I cannot figure out how to get the values for nonroot_risk and nopasswd_risk from my model to display in the form.
Related
I am trying to change what is displayed when I click on a model in the django admin. For example if I have the model Book and then I go into the admin panel and click book, it will give me all the fields that I created the model with.
But I want to edit that page that shows all that data. For example, if I click on the "Book" model in the admin panel and see my fields to edit, I want to put another bit of fields on the bottom from another model. Or maybe I want to put like a "Similar Books" list. Is it possible to edit this page?
Admin customization information is here. You can do stuff like list_display or fieldsets etc.
I am trying to add a filter to my ManyToMany field.
I have a model User and a model Notification. Notification is connected with User by a ManyToMany field. I want to be able to send a Notification to all users that are for example located in Bulgaria or filter them based on another property in the user model which is not predefined(i.e. The person who creates the Notification does not know pre-creation the filter field).
I tried using raw_id_fields for User in Notification admin page. I can then chose and filter Users I want to add based on filters in the Model but I can only choose one user at a time and if I have to add, for example 10k users this can be quite inconvenient.
I want to be able to either use raw_id_field and select multiple instances at once, or add some field filtration to filter_horizontal or I don't know.
I believe what your looking for is this:
list_filter = ['user__located']
That will let you filter Notifications by the located attribute on Users.
I have an django site for new articles , in which multiple user write articles.
I want to make an action for selecting a user , so that If I choose a particular user , I can only see its updation/insertion in admin site.
If updation/insertion is part of a model that has an foreign key to USER model, then just write an admin-inlline to show a list of them in the user page below all other fields
How to create two forms: (login form, register form) and they submitted to my component.and admin has to approve registred user
You can use default User Manager com_users in Joomla , You just need to create a menu then assign the Menu Item Type to Login Form/Registration Form under the user manager list and enter the further details and just save it.
More detail you can find here :
Help25:Users User Manager
Help25:Menus Menu Item User Login
Help25:Menus Menu Item User Registration
Hope this will help you.
I have a Customer model which contains a ForeignKey to a Contact model.
I have over 100,000 contacts in my DB and when I load the admin page for a specific customer, the dropdown menu for the contact is getting populated with ALL of the contacts in the database. This has recently, due to its shear length, started causing my Firefox to crash while the admin page is loading.
Is there a way to either:
replace the field with an integer
field I can manually modify to the
contact ID when necessary
replace the dropdown menu with some
alternative input method which won't
crash the browser
remove this input
from the Customer admin page
altogether
Thanks!
You can do any of the either of things you want to.
Simplest solution is the exclude the field from the admin. Just say so in the admin class.
You can change the field to be text input and display it's primary key rather than the item itself, by including it in the raw_id_fields of the admin class.
You can also replace the standard dropdown widget with the Auto complete text field input. Use the implemented widget, or other equivalents. - This is probably the solution you like the best.
You can also override the formfield_for_foreignkey method on the Admin model to customize the queryset that gets displayed in the foreign-key dropdown. You may want to checkout my implementation for displaying only the current User's (or subdomain's) added entities.
Sounds like specifying the contact field in raw_id_fields in your admin.py entry for the relevant model would sort you out. Docs are here.
PS. Surprised (but not that surprised) that FF gives out before your database server tanks...