简体   繁体   English

Django:如何根据登录用户自定义显示

[英]Django: How to customize display based on the logged in user

creating an attendance system where lecturers register and login using their lecturer code and password different lecturers teach different subjects, currently, the "subject" page displays all subjects present in the database创建一个考勤系统,讲师使用他们的讲师代码和密码注册和登录不同的讲师教授不同的科目,目前,“科目”页面显示数据库中存在的所有科目

as such i would like the "subject" page to display only the subjects taught by the specific lecturer因此,我希望“主题”页面仅显示特定讲师教授的主题

how can i achieve that?我怎样才能做到这一点?

(ps. still a beginner in django..a detailed answer or resources will be highly appreciated) (ps. 在 django 仍然是初学者..将非常感谢详细的答案或资源)

Source code https://github.com/Zainab692/Fyp2/tree/master/django-project/cms源代码https://github.com/Zainab692/Fyp2/tree/master/django-project/cms

Instead of subject=Subject.objects.all() you need to filter it.而不是subject=Subject.objects.all()你需要过滤它。 Here it filters by if the "name" contains "Foo"如果“名称”包含“Foo”,则在这里进行过滤

subject=Subject.objects.filter(lecturer_name__name__contains="Foo")

You can use this as a GET query parameter like this: Capturing URL parameters in request.GET您可以将其用作 GET 查询参数,如下所示: Capturing URL parameters in request.GET

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 django:如何根据用户自定义ModelAdmin表单的显示? - django: How to customize display of ModelAdmin form based on user? 如何在基于django框架类的视图中过滤以仅显示属于已登录用户的交易的销售额 - How can to filter to display only sales for transactions that belong to logged in user in django framework class based view 基于django的用户身份验证 - User Authentication based on if logged in or not django django:如何显示每个模板中登录的用户? - django: how to display user logged-in in each template? 在 Django 中如何显示来自当前登录用户的数据 - In Django how to display data from current user that's logged in 我如何在 django 中为特定登录用户显示特定页面 - How i display specific page for specidfic logged in user in django 如何根据登录的用户在 django 模板中显示某些内容? - How to display something in a django template according to which user is logged in? 如何根据当前登录用户查询 Django ModelForm 字段中的下拉列表 - How to query a dropdown in a Django ModelForm field based on current logged in user 根据与当前登录的用户相关的用户配置文件,仅显示 django 管理员上的那些对象 - Display only those objects on django admin based on the user profile which is related to user that has logged in currenty Django基于类的视图-如果用户已登录,则重定向 - Django Class Based View - redirect if user is logged in
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM