吴秀峰

  • 内容:``` python User.objects.filter(**kwargs) ``` 用可变参数来实现。

  • 内容:需要贴出对应代码才可分析。

  • 内容:class CourseAdmin(admin.ModelAdmin): #指定用户只能查看自己用户下的东西 def get_queryset(self, request): qs = super(CourseAdmin, self).get_queryset(request) if request.user.is_superuser: return qs return qs.filter(user=request.user) list_display = ('id','title','course','user','views','modified_time') list_display_links = ('id', 'title') actions_on_bottom = True search_fields = ['title'] list_editable = ['views'] # filter_horizontal=['user'] # date_hierarchy = 'modified_time' # exclude = ('user',) #排除某些字段在后台显示 #raw_id_fields = ('user',) # list_select_related = ('user', 'course') #指定某字段只能自己查看属于自己用户下的字段 def formfield_for_foreignkey(self, db_field, request, **kwargs): if db_field.name == "user": kwargs["queryset"] = Userinfo.objects.filter(username=request.user) if db_field.name == "course": kwargs["queryset"] = Category.objects.filter(user=request.user) return super().formfield_for_foreignkey(db_field, request, **kwargs)

  • 内容:给留言加一个专门用来审核的布尔字段,默认为False,在后台修改为True之后,才在前端显示。

  • 内容:这种数据库见得少呀