我的django观点如下:
#view to retrieve all the exercises
def exercise_all(request):
"""
List all exercises.
"""
if request.method == 'GET':
exercises = Exercise.objects.all()
serializer = ExerciseSerializer(exercises, many=True)
return JSONResponse(serializer.data)
#view to retrieve initial default list of exercises, this will be called on angular controller load
def exercise_initial(request):
"""
Gives the first exercise.
"""
if request.method == 'GET':
exercises = Exercise.objects.filter(exercise_type=1 , intensity_level=1)
serializer = ExerciseSerializer(exercises, many=True)
return JSONResponse(serializer.data)
#view to retrieve all specific exercises
def exercise_next(request, exType, level):
"""
Gives the next exercise.
"""
if request.method == 'GET':
exercises = Exercise.objects.filter(exercise_type=exType, intensity_level=level)
serializer = ExerciseSerializer(exercises, many=True)
return JSONResponse(serializer.data)
我的网址:
url(r'^exercises/all/$', views.exercise_all),
url(r'^exercises/initial/$', views.exercise_initial),
url(r'^exercises/(?P<exType>\d)/(?P<level>\d)/$', views.exercise_next),
我的角度控制器调用这些视图:
.controller('videoCtrl', function($scope,$http, $sce, $ionicPopup, djangoAuth) {
$scope.exercise_type='';
$scope.exercise_description='';
$scope.exercise_video_url='';
/** To fetch the initial exercise **/
$http.get("https://localhost:8000/api/exercises/initial/").then(function(response){
$scope.initial_data=response.data;
angular.forEach($scope.initial_data, function(item){
$scope.exercise_type=item.exercise_type;
$scope.intensity_level=item.intensity_level;
$scope.exercise_description=item.description;
$scope.exercise_video_url=$sce.trustAsResourceUrl(item.video_url);
})
});
//Function to play next video
$scope.playNextTest = function(){
alert("Next exercise: " + ($scope.exercise_type+1)); //demo line, logic needs to be implemented here
}
我想要实现的目标:
如何实现这一目标?