TastyPie の出力に表示されるように、多数の ForeignKey 関係を取得しようとしています。これが私のモデルです:
class Report(models.Model):
safetyreportid = models.SlugField("Safey Report Unique Identifier", max_length=125, primary_key=True)
safetyreportversion = models.IntegerField("Safety Report Version Number", max_length=125, blank=True, null=True)
primarysourcecountry = models.CharField("Country of the primary reporter", max_length=3, blank=True)
occurcountry = models.CharField("Country where the event occured", max_length=3, blank=True)
class Reaction(models.Model):
report = models.ForeignKey(Report)
reactionmeddrapt = models.CharField("MedDRA Preferred Term used to characterize the event", max_length=250, blank=True)
reactionmeddraversionpt = models.CharField("MedDRA version for reaction/event term PT", max_length=100, blank=True)
と私の API.py ファイル:
class ReactionResource(ModelResource):
class Meta:
queryset = Reaction.objects.all()
resource_name = 'reaction'
class ReportResource(ModelResource):
reaction = fields.ForeignKey(ReactionResource, attribute='reaction', full=True, null=True)
class Meta:
queryset = Report.objects.all()
resource_name = 'report'
ただし、関係(django管理パネルで確認できます)が存在する場合でも、JSON出力で取得できるのは次のとおりです。
reaction: null,
何か案は?