ChangeList is in the file /python**/Lib/site-packages/django/contrib/ admin/views/main.py ,and we use ModelAdmin so change_view function can direct to be used.
On 5月21日, 下午2时08分, rahul jain <[email protected]> wrote: > Hi Danfi, > > Thanks for your quick response. But can you explain a little more how > can we connect ChangeList class with that function change_view. > Confuse about it. > > --RJ > > 2010/5/20 Danfi <[email protected]>: > > > > > In Auth group you can create a group and set the limits. > > > see different panel maybe use changelist_view > > > I saw this just be similar to yours' > > > class Part(models.Model): > > is_deleted = models.BooleanField() > > ////////////////////////////////////////////// > > class PartAdmin(admin.ModelAdmin): > > actions =None > > def change_view(self, request, object_id, extra_context=None): > > if Part.objects.get(id=object_id).is_deleted==True and > > request.user.is_superuser == False: > > return HttpResponseRedirect('/admin/') > > else: > > return super(PartAdmin, self).change_view(request, > > object_id,extra_context=None) > > > ///////////////////////////////////// > > edit admin/views/main.py > > IS_DELETED_VAR = 'is_deleted' > > > class ChangeList(object): > > def __init__(self, request, model, list_display, list_display_links, > > list_filter, date_hierarchy, search_fields, list_select_related, > > list_per_page, list_editable, model_admin): > > self.model = model > > self.opts = model._meta > > self.lookup_opts = self.opts > > self.root_query_set = model_admin.queryset(request) > > try: > > f =self.lookup_opts.get_field(IS_DELETED_VAR) > > except models.FieldDoesNotExist: > > self.root_query_set = self.root_query_set > > else: > > if isinstance(f,models.BooleanField) and (request.user.is_superuser == > > False): > > self.root_query_set = self.root_query_set.exclude(is_deleted = 'True') > > else: > > self.root_query_set = self.root_query_set > > > On 5月21日, 下午12时01分, rahul jain <[email protected]> wrote: > >> Hi Everyone, > > >> I would like to implement different views in admin panel based on the user. > > >> if the user is any other user apart from admin > > >> then for all those models, the user should just be able to see those > >> objects,( no change, delete and add). > >> Those users should also not see the select boxes or basically select all. > > >> So by default django provides three permissions, add, delete,change. I > >> would like to add one more permission on admin panel. > > >> I know this could be done on our own views through this > > >> class USCitizen(models.Model): > >> # ... > >> class Meta: > >> permissions = ( > >> ("can_drive", "Can drive"), > >> ("can_vote", "Can vote in elections"), > >> ("can_drink", "Can drink alcohol"), > >> ) > > >> {% if perms.foo %} > >> <p>You have permission to do something in the foo app.</p> > >> {% if perms.foo.can_vote %} > >> <p>You can vote!</p> > >> {% endif %} > >> {% if perms.foo.can_drive %} > >> <p>You can drive!</p> > >> {% endif %} > >> {% else %} > >> <p>You don't have permission to do anything in the foo app.</p> > >> {% endif %} > > >> But how to do the same thing on the django admin. Also, how to remove > >> the select all functionality for selected users. > > >> --RJ > > >> -- > >> You received this message because you are subscribed to the Google Groups > >> "Django users" group. > >> To post to this group, send email to [email protected]. > >> To unsubscribe from this group, send email to > >> [email protected]. > >> For more options, visit this group > >> athttp://groups.google.com/group/django-users?hl=en. > > > -- > > You received this message because you are subscribed to the Google Groups > > "Django users" group. > > To post to this group, send email to [email protected]. > > To unsubscribe from this group, send email to > > [email protected]. > > For more options, visit this group > > athttp://groups.google.com/group/django-users?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group > athttp://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

