Very slow responses from tastypie. What can I do?

For a long time to describe the problem I'm at the bottom of the question attached video. Main parts of code:
# MODELS.PY
class Movie(models.Model):
 class Meta:
 db_table = 'movies'

 id = models.AutoField(db_index=True, primary_key=True)
 nameru = models.CharField(max_length=255)
 nameen = models.CharField(max_length=255)
#{...}
 sequels = JSONField(default=[])
 recommendations = JSONField(default=[])
 budget = JSONField(default={
 'currency': 'USD',
 'budget': 0
})

class Staff(models.Model):
 class Meta:
 db_table = 'movie_staff'

 name = models.CharField(max_length=255)
 name_en = models.CharField(max_length=255)
 birth_date = models.DateTimeField()
#{...}
 photo = models.ImageField()

 def __str__(self):
 return "{0} ({1})".format(self.name, self.name_en)


class StaffTag(models.Model):
 class Meta:
 db_table = 'tag_staff_movie'

 role = models.CharField(max_length=255)
 movie_id = models.ForeignKey(Movie, on_delete=models.CASCADE, db_index=True)
 staff_id = models.ForeignKey(Staff, on_delete=models.CASCADE, db_index=True)

# RESOURCES.PY
class MovieStaffResource(ModelResource):
 movie_id = fields.IntegerField(attribute='movie_id_id') #ForeignKey can be seen As not used, so you can score a chat with the film itself
 person = fields.ForeignKey(StaffLessResource, attribute='staff_id', full=True)

 class Meta:
 queryset = StaffTag.objects.all()
 allowed_methods = ['get']
 resource_name = 'moviesFilmStaff'
 authorization = Authorization()
 filtering = {
 'movie_id': ALL
}

@staticmethod
 def group_objects_by_role(data, objects: List[dict]):
 # TODO write test;
 result = {}
 for obj in objects:
 role = obj['role']
obj.update(obj['person'])
 del obj['person']
 if role not in result:
 result[role] = []
result[role].append(obj)
else:
result[role].append(obj)
 data['objects'] = result
 return data

 def get_list(self, request, **kwargs):
 #Here it is possible not to pay attention... just add a method of grouping objects according to the roles...
 resp = super(MovieStaffResource, self).get_list(request, **kwargs)
 data = json.loads(resp.content.decode()) # type: dict
 data = self.group_objects_by_role(data, data['objects'])
 data = json.dumps(data)
 return HttpResponse(data, content_type='application/json', status=200)

class StaffLessResource(ModelResource):
 id = fields.IntegerField(attribute='id')
 class Meta:
 queryset = Staff.objects.all()
 allowed_methods = ['get']
 resource_name = 'moviesStaffLess'
 authorization = Authorization()

https://www.youtube.com/watch?v=dF2CkOgb0aI
Sorry for the confusion, but I hope the question is clear.
And all thanks in advance)
July 2nd 19 at 16:39
1 answer
July 2nd 19 at 16:41
Solution
StaffTag.objects.select_related()
Unfortunately, did not help.. time has increased significantly (more than 2 times)... though it is necessary to examine in more detail select_related() - brycen_Ledner16 commented on July 2nd 19 at 16:44
By the way thank you) select_related() now work with him...
Might methods something better, then you can experiment - brycen_Ledner16 commented on July 2nd 19 at 16:47
Help! Thank you for the advice) - brycen_Ledner16 commented on July 2nd 19 at 16:50

Find more questions by tags Django