Administrator user view and user restriction

I want to create a custom view in django admin that reflects the change form from another model. I got to creating a custom admin class class and don't know where to go from here. I cannot find good examples for Django 1.8 on how to create a custom view.

Django Version: 1.8

class CustomerProductOrderAdmin(admin.ModelAdmin): review_template = 'admin/onlineordering/order_template.html' def get_urls(self): urls = super(CustomerProductOrderAdmin, self).get_urls() my_urls = patterns('', (r'\d+/customer_template/$', self.admin_site.admin_view(self.customer_template)), ) return my_urls + urls def customer_template(self, request, id): product_orders = CustomerProductOrder.objects.get(pk=id) return render_to_response(self.review_template, { 'quantity': 'Quantity: %s' % product_orders.quantity, }, context_instance=RequestContext(request)) 

I have a customer table related to this user table.

 class Customer(models.Model): customer = models.ForeignKey(settings.AUTH_USER_MODEL, limit_choices_to={'groups__name': "customers"}) 

/ app / model / 1 #pk = customer.id

Custom form will have this URL

/ app / customform /

When an incoming user goes to / app / customform, they should not see the change form from / app / model / 1. They should not see other users changing forms. In addition, I would like to restrict access to a user form to a specific user group. those. this group cannot see / app / model /, but can see / app / customform.

+8
django-admin
source share
1 answer

Example of adding an independent template to the admin page

In the model.py file inside the model class add the function

 def version_summery(self, ): batch_d= {} fy = {} for br in self.batchresult_set.all(): batch_d[br.name.strip()] = br.__dict__ fy['batch_d'] = batch_d.values() x = render_to_string('admin/results/result_build_summary.html', fy) return x 

make sure urls.py knows how to find the template "result_build_summary.html"

and in admin.py file

 readonly_fields = ( 'version_summery',) fieldsets = ( ('', { 'fields': ( 'version_summery', ), }), ) 
0
source share

All Articles