更新时间:2023-11-13 21:58:10
这不是一个完整的解决方案,但它会让您知道从哪里开始.
This is not a complete solution, but it will give you an idea of where to start.
mainsite
中创建一个UserProfile
模型.这将保存两种类型用户的任何共同属性.使用 OneToOne(...)
字段将其与 User
模型相关联.Business
和 Student
,它们具有 OneToOne
关系,每个模型都与 UserProfile
(或从 UserProfile
继承).这将保存特定于该类型用户的属性.文档:多表继承/一对一关系
UserProfile
中添加一个字段来区分它是企业还是学生的个人资料.UserProfile
model in mainsite
. This will hold any common attributes for both types of users. Relate it to the User
model with a OneToOne(...)
field.Business
and Student
, which have OneToOne
relationships each with UserProfile
(or inherit from UserProfile
). This will hold attributes specific to that type of users. Docs: Multitable inheritance / OneToOne RelationshipsUserProfile
to distinguish whether it is a business or student's profile.然后,对于内容管理:
save()
函数以自动检查冲突(例如,Business
和 Student
都有一个条目与 UserProfile
,或没有条目).__unicode__()
表示.save()
functions to automatically check for conflicts (e.g. There is an entry for both Business
and Student
associated with a UserProfile
, or no entries).__unicode__()
representations where necessary.