如何在 TastyPie 中组合多个资源?我想组合 3 个模型:用户、个人资料和帖子。
理想情况下,我希望配置文件嵌套在用户中。我想从 UserPostResource 公开用户和所有配置文件位置。我不知道从这里去哪里。
class UserResource(ModelResource):
class Meta:
queryset = User.objects.all()
resource_name = 'user'
fields = ['username','id','date_joined']
#Improper Auth
authorization = Authorization()
class UserProfileResource(ModelResource):
class Meta:
queryset = UserProfile.objects.all()
resource_name = 'profile'
class UserPostResource(ModelResource):
user = fields.ForeignKey(UserResource,'user', full=True)
class Meta:
queryset = UserPost.objects.all()
resource_name = 'userpost'
#Improper Auth
authorization = Authorization()
这是我的模型:
class UserProfile(models.Model):
user = models.OneToOneField(User)
website = models.CharField(max_length=50)
description = models.CharField(max_length=255)
full_name = models.CharField(max_length=50)
class UserPost(models.Model):
user = models.ForeignKey(User)
datetime = models.DateTimeField(auto_now_add=True)
text = models.CharField(max_length=255, blank=True)
location = models.CharField(max_length=255, blank= True)