일반 외래 키를 사용하여 auth.User
에서 상속 된 Users
모델로 다른 프로필을 연결합니다. --natural
옵션을 전달했지만 dumpdata
을 수행 할 수 없습니다. 그것은,Django : 일반 외래 키 dumpdata : 종속성을 해결할 수 없습니다.
오류 : myproject.AdminProfile, myproject.TeacherProfile, myproject.appers 직렬화 애플 리케이션 목록에 대한 종속성을 해결할 수 없습니다.
documentation에 따르면, 일반적인 관계를 포함하는 조명기를 가져오고 점멸하려면 natural_key methods을 구현해야한다고합니다. 여기에 제시된 모델로 어떻게 할 수 있습니까?
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 및 Postrgres 사용.
*이 문제는 모델 간의 순환 종속성 (자체 참조가있는 모델 포함) *이있는 경우 나타납니다. 정보 주셔서 감사합니다. 실제로 나는 자기 참조 필드를 가지고 있었다. 처음 추가하지 못해 죄송합니다 (지금 수정 확인). 제가 그것을 제거하면 나는 덤프를 얻을 수 있습니다. 하지만 어쨌든 그 분야가 필요합니다. 그게 가능하니? 아니면 그 모델을 유지하기 위해 다른 모델을 만들어야합니까? – Babu
@Babu 그게 다야! 업데이트 된 답변을 확인하십시오. 코드가 1.2.5 및 1.5b2 (이 버그는 이미 수정 된 위치)에서 제대로 작동하지만 1.4에서는 작동하지 않습니다 (1.3에서도 1.3으로 추정하지 않습니다). – mgibsonbr
상세한 답변과 멀티 버전 테스트 결과를 보내 주셔서 감사합니다. :) 그럼 다른 모델을 만들어 보겠습니다. 1.4에서 고정되어 있지 않은 것은 매우 이상하고 동정입니다. – Babu