I need to add a custom view to a model admin similar to the history view. For example if I have a model called Job I can access the history by going to /jobs/job//history/. How do I add another view that will respond to a pattern like /jobs/job//workflow/?
You can define get_urls() on your Admin to add more admin views.
don't forget the admin_view() wrapper
if you wanted to add a view for an individual object (like the change form), just add the object id to your url pattern, then in your view (try to) grab the corresponding object.
It's up to you to provide the links (for example, by overriding the base (/change_form) template and adding a new item to the "object-tools" list).
Related
By default, the create contact form from Contacts and create Vendor form from Purchase appears to have the same External ID ie, base.view_partner_form. I want to replace the form view for create contact. Now, i know that to replace a view i'll have to do this in my custom form view.
<field name="inherit_id" ref="external_id_of_form"/>
So how can i replace the form view in this case so that only the contact create form gets replaced? Can i replace the form view based on action? `
You're not "replacing" by inheriting, but changing/extending other views.
Indeed you should change the menu actions, because it is possible to set the target views.
But there is more than one approach. I'll try to list some of them, plus you can combine them.
full single views
one or more ir.ui.view of same type for the same model
can be referenced in actions and code
only one of them can be the default view of that type, which odoo will use for example in actions without a view reference, keep that in mind!
one base form with different extension views
one base view for a model
multiple primary extension views to that base view
you can either use those primary extensions as reference in actions
or you can set security groups in those extensions to show these extensions only to users of those groups
one view with extension views
that's the usual approach
you have a base view and lot of extensions
visibility is defined in the arch with groups, attrs, invisible, etc.
IMO the best approach for you is the first one. An Odoo example are the views for model account.invoice, because there are two form views: one for customer invoices and one for supplier invoices.
I have this simple Django app which uses admin panel as a user portal to add and delete model objects.On addition of each model object I am adding a related data file in S3, how can I get the list of objects requested for deletion from the "delete selected" action, so that the particular object's file in S3 can be deleted.
I tried searching for the related function definition in admin.ModelAdmin class but no help.
I thing you can override delete action in django admin panel using this documentation. You should just add your own delete action.
You can use the post_delete signal: https://docs.djangoproject.com/en/2.1/ref/signals/#post-delete on the model so it will work in admin but also when a record is deleted from any place in app.
i'm creating a app.it has manytomany field to store data about class and students.
urls.py
url(r'^class/(?p<title>[-\w]+)/(?p<id>[\d]+)/',views.list,name ='list'),
Basically one user(Teacher) can create many class_room .Each class_room have one title and many students following in that class.
problem is:
Each class_room have unique url. Eg (mywebsite.com/science/88/) this link is access only for following students not for anonymous user.This is a loop hole if any non following students try some random url like this they could see the page (mywebsite.com/maths/2500/).
How to restrict a student from access a page which he is not following?
the UserPassesTestMixin mixin can be used to this effect. Basically, write a View Class that implements the test_funcfunction. This function has access to self so you can read the URL and the user. if the test_func returns True, the user is allowed to go on, otherwise is passed to access control (probably redirected to the login form if configured).
I'm really confused how I can change the registration_form to ask the users about their first and last name.
I think I need to manipulate subclass RegistrationView from registration.backends.simple.views but I don't know how to do this to show first and last name in registration form.
You should be able to sub-class RegistrationForm and add the fields you want.
Look at the source for the default forms on how to do so:
https://github.com/macropin/django-registration/blob/master/registration/forms.py
I have this file:
templates/admin/{app_name}/{model_name}/add/change_form.html
This extends
admin/change_form.html
I added a button to this template and it is working fine WHEN adding a new instance of the model.
I want to add another button the template that appears WHEN changing already existing instance of a model. So I created this file:
templates/admin/{app_name}/{model_name}/change/change_form.html
thinking that add and change use the same template. But changes I made to this template do not seem to take place.
What template does Django use when changing the fields of already existing instance of a model?
You can specify the change_form_template in your model admin.
By default it's (in this order):
admin/APP/MODEL/change_form.html
admin/APP/change_form.html
admin/change_form.html
The model properties could be passed in GET to the template url.