1👍
Your relationship looks reversed.
The ForeignKey
between the Models does Reaction
-> Report
, but in your API, it’s ReportResource
-> ReactionResource
.
0👍
The correct answer to your problem, in case you want to see the reactions inside the report is including a reverse ForeignKey from the Report
to the Reaction
resources:
class ReportResource(ModelResource):
reaction_set = fields.ToManyField('yourapp.resources.ReactionResource', 'reaction_set', full=False)
class Meta:
queryset = Report.objects.all()
resource_name = 'report'
class ReactionResource(ModelResource):
report = fields.ForeignKey(ReportResource, 'report', full=True, null=True)
class Meta:
queryset = Reaction.objects.all()
resource_name = 'reaction'
This ToManyField will show up all the reaction resources URIs to in the reaction_set
field. The name of the Resource has to be a full string path, given that the Resource has still not been declared. Hope it helps.
Source:stackexchange.com