Django中的用户对象出现问题 [英] Trouble understaing User Object in Django

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

问题描述

我正在学习django并创建一个网络应用程序,客户端注册进行购买,而且供应商也可以添加他/她的产品进行销售。在阅读django上的文档之后,我仍然不清楚由django提供的内置对象中的用户。我的问题是:

I'm learning django and creating a web app where a clients signs up to make a purchase and also a vendor can add his/her product for sale. After reading the documentation on django, I'm still not clear on the User in built Object provided by django. My question is:


  1. 我应该使用内置对象中的用户来满足我的要求。但是阅读文档后,User对象似乎主要适用于管理员权限/超级用户,或者我错了。

  1. Should i use the User in built object to satisfy my requirements. But after reading the documentation it seems the User object is mostly suited for admin privileges/superuser or am i wrong.

由于我将拥有2个用户,意味着在数据库中有2个不同的模型。将有2个不同的意见。客户或用户只看到要出售的产品,供应商只能看到他/她希望出售的仪表板和产品。

Since i will be having 2 Users, meaning having 2 different models in database. There will be 2 different views. The client or users only sees products for sale and vendor only sees his dashboard and products he/she wishes to put up for sale.

从Java角度来看,我可以创建一个Client类和一个Vendor类,但是我想这样做django,似乎从我从他们建议使用User对象的文档中读取的内容。请问我该怎么做,或者有人给出一个如何去做的例子。感谢非常感谢..

Coming from a Java perspective i could just create a Client class and a Vendor class but i want to do this in django and it seems from what i have read from the documentation they suggest to use the User object. Please how do i go about this or could someone give an example of how to go about this. Thanks much appreciated..

推荐答案

你是正确的,java透视图是数据库透视图,对django也是如此:

You are correct, the java perspective is the database perspective, which is true for django as well:

from django.contrib.auth.models import User

class Client(models.Model):

   user = models.OneToOneField(User)
   # ... more Client fields here

class Vendor(models.Model):

   user = models.OneToOneField(User)
   # ... more Vendor fields here

请注意,这些模型允许用户成为客户端和供应商,或者根本不需要。如果用户只能是客户端供应商,或者必须是其中一个类,则需要进行其他验证。用户模型将用于所有人的常见功能,例如身份验证或其他共享功能(例如使用电子邮件发送通知)。

Note that these models allow a user to be a client and a vendor - or none at all. If a user can be only be a client or a vendor, or must be one of those classes, you will need additional validation. The User model will be used for the common features to all, such as authentication or other shared features (e.g. using the email to send a notification)

这篇关于Django中的用户对象出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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