Hi, I am new to django and tastypie. I am trying to add a list of
model objects returned from a query to my resource.
I have the following model in django:
class League(models.Model):
name = models.CharField(max_length=100, verbose_name=u'Ligin Adı')
start_date = models.DateField(verbose_name=u'Ligin başlama
tarihi')
end_date = models.DateField(verbose_name=u'Ligin bitiş tarihi')
class LeagueRegistration(models.Model):
team = models.ForeignKey(Team)
league = models.ForeignKey(League)
I defined the following resource:
class LeagueResource(ModelResource):
class Meta:
queryset = League.objects.all()
resource_name = 'league'
def dehydrate(self, bundle):
bundle.data['registrations'] =
LeagueRegistration.objects.filter(league=
bundle.obj.pk)
return bundle
I want to return the league with its registrations. The query is
working fine but the value of registration fiels is not serialized
into json:
"registrations":
"[<LeagueRegistration>,<LeagueRegistration>,<LeagueRegistration>]"
How can I make this list to be serialized into json before returning?