如何在Django中分离用户帐户? [英] How do I separate user accounts in Django ?

查看:32
本文介绍了如何在Django中分离用户帐户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Django创建一个允许记录医疗信息的应用程序,但是我在区分用户帐户时遇到问题,因此当前所有用户都可以看到输入的相同信息.熟悉django的人都知道如何设置适当的权限和角色,并愿意为新手提供帮助吗?

I am using Django to create an app that allows recording of medical information however I am having problems with seperating the user accounts so currently all users see the same information entered. Anyone familiar with django knows how to set the proper permissions and roles and is willing to help a newby out?

我希望用户仅访问该用户创建的帐户和该用户创建的记录.

I want the user to only access to the account the user creates and the records that the user create.

这是我的github 链接

This is my github link

如果您能提供帮助,我将不胜感激.

If you are able to to help I would really appreciate it.

推荐答案

如果只想列出/home 中的用户记录.您只需要将home/views.py中的查询从 Identity_unique.objects.all()更改为 Identity_unique.objects.filter(user = request.user)

If you want to list only the user's records in your /home . You only need to change the query in your home/views.py, from Identity_unique.objects.all() to Identity_unique.objects.filter(user=request.user)

Identity_view(TemplateView)类:

class Identity_view(TemplateView):

def get(self, request):
    form = Identity_form()
    Identities = Identity_unique.objects.filter(user=request.user)
    var = {'form': form, 'Identities': Identities}
    return render(request, self.template_name, var)

或者,如果您想在Django Admin面板中过滤对象,则应阅读以下内容:

Or if you want to filter objects in your Django Admin panel you should read this:

这篇关于如何在Django中分离用户帐户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆