我使用通用外键将不同的配置文件与Users
继承自auth.User
. dumpdata
尽管通过了--natural
选项,但我无法做到。它说,
错误:无法解析序列化应用列表中 myproject.AdminProfile、myproject.TeacherProfile、myproject.Users 的依赖关系。
根据文档,据说我们需要实现natural_key 方法来获取和闪烁涉及泛型关系的固定装置。我怎么能用这里展示的模型做到这一点?
class Users(User):
location = models.TextField('Location', blank=True)
created_by = models.ForeignKey('self', null=True, blank=True, related_name='created_by_user')
# Generic foreign key setup to hold the extra attributes
profile_contenttype = models.ForeignKey(ContentType, null=True, blank=True)
profile_object_id = models.PositiveIntegerField('Extra ID', null=True, blank=True)
profile_object = generic.GenericForeignKey('profile_contenttype', 'profile_object_id')
class AdminProfile(models.Model):
organization = models.CharField('Organization', max_length=100)
# profile reverse relation to get the user
users_link = generic.GenericRelation('Users', content_type_field='profile_contenttype',
object_id_field='profile_object_id')
class TeacherProfile(models.Model):
designation = models.CharField('Designation', max_length=100)
# profile reverse to get the user
users_link = generic.GenericRelation('Users', content_type_field='profile_contenttype',
object_id_field='profile_object_id')
使用 Django 1.4.3 和 Postgres。