我有一个资源,我试图在其中公开它的选票。
class ViewPostResource(ModelResource):
user = fields.ForeignKey(UserResource,'user',full=True)
votes = fields.ToOneField('voting.resources.GetVotesResource', attribute='vote_set', full=True)
class Meta:
queryset = UserPost.objects.all()
resource_name = 'posts'
include_resource_uri = False
class GetVotesResource(ModelResource):
user = fields.ForeignKey(UserResource,'user', full=True)
class Meta:
queryset = Vote.objects.all()
resource_name = 'vote'
不过,我的投票模型与正常情况有些不同。如何使用以下模型设置公开帖子的投票?
class Vote(models.Model):
user = models.OneToOneField(User, related_name='vote')
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
object = generic.GenericForeignKey('content_type', 'object_id')
vote = models.SmallIntegerField(choices=SCORES)