注册时如何设置多种用户类型?

发布于 2024-09-08 06:23:09 字数 317 浏览 1 评论 0原文

我正在使用 Django 1.2,我想要两种用户类型(一种用于公司,一种用于顾问)。我将在我的模型中使用一个对象(类似于 is_company 或 is_consultant 的布尔值)或 Django 的组来区分它们 - 取决于哪个更容易解决这个问题。我想如果我不是一个完全的菜鸟,这不会有太大的问题;)

我使用 django-registration 作为我的身份验证后端,并且我将在我的网页上为每种用户类型(公司与用户)提供一个单独的表单顾问)。我认为最好不要为这两种情况创建几乎相同的两个不同视图,因此我想知道识别/注册以这两种类型之一注册的用户的最佳方法是什么。

感谢您的帮助。

I'm using Django 1.2 and I want to have two user types (one for companies and one for consultants). I will either use an object in my model (something like a boolean for is_company or is_consultant) or Django's groups to distinguish them--depending on which is easier for this problem. I guess it wouldn't be much of a problem if I weren't a total noob ;)

I'm using django-registration for my authentication backend, and I will have a separate form on my webpage for each user type (company vs consultant). I don't think it is best to create two different views that are almost identical for the two cases, so I'm wondering what the best way is to identify/register the users who signed up as either of the two types.

Thanks for your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

倾听心声的旋律 2024-09-15 06:23:09

您希望用户在注册时选择是顾问还是公司?如果是这样,您可以通过子类化 RegistrationForm 来创建自己的表单,然后将新表单传递到 django-registration 的参数中(阅读有关如何执行此操作的文档。)

要对表单进行子类化并添加您将执行以下操作的附加字段:

from registration.forms import RegistrationForm

USER_TYPES = (
   ('consultant', 'Consultant'),
   ('company', 'Company'),
)

class MyRegistrationForm(RegistrationForm):
     user_type = forms.ChoiceField(choices=USER_TYPES)

从那时起,您应该捕获信号并根据需要处理表单数据 django-registration 有很棒的文档

希望这就是您所寻找的。

Do you want the user to pick if they are a consultant or company when registering? If so, you can create your own form by subclassing the RegistrationForm and then passing your new form into the parameters for django-registration (Read the doc on how to do that.)

To subclass the form and add the additional field you would do something like so:

from registration.forms import RegistrationForm

USER_TYPES = (
   ('consultant', 'Consultant'),
   ('company', 'Company'),
)

class MyRegistrationForm(RegistrationForm):
     user_type = forms.ChoiceField(choices=USER_TYPES)

From then, you should catch the signal and do as you need with the form data django-registration has great documentation

Hope that's what you were lookign for.

作死小能手 2024-09-15 06:23:09

您可以在查询字符串中传递信息,而不是查看 POST。
因此,一个“按钮”(实际上只是一个链接)链接到 /form?type=consultant,另一个链接到 /form?type=company,然后您可以从GET信息中抓取

Rather than looking in the POST, you can pass the information in the query string.
So one "button" (which is really just a link) links to /form?type=consultant, and the other links to /form?type=company and then you can grab it from the GET information

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文