Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. AttributeError: 'JsonResponse' object has no attribute 'all_records'
  2.  
  3. from sanic.response import json
  4. from sanic.views import HTTPMethodView
  5.  
  6. from models.project import Project
  7. from helpers.json import JsonResponse
  8.  
  9.  
  10. class ProjectListResource(HTTPMethodView):
  11. def get(self, resp):
  12. projects = Project().select().dicts()
  13. return JsonResponse(projects, all_records=True)
  14.  
  15. from sanic.response import json
  16.  
  17. class JsonResponse:
  18. def __init__(self, model, all_records=None):
  19. self.model = self._model_query(model)
  20. self.all_records = all_records
  21.  
  22. def _model_query(self, model):
  23. if self.all_records:
  24. records = json({model: list(model)})
  25. else:
  26. records = {}
  27.  
  28. return records
  29.  
  30. def __init__(self, model, all_records=None):
  31. self.all_records = all_records # Сначала эта строка
  32. self.model = self._model_query(model) # И только потом эта
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement