Getting each values from a value list python
Question: Hi I have a custom Django/python resource/view. as follows

    
    
    class ResourceView(JSONResponseMixin, View):
    
    def get(self, request, *args, **kwargs):
        status = 'error'
        msg = "Success"
        # Getting the x value from url/queryset
        x= self.request.GET.get('x')
        mas = self.request.GET.get('mas')
    
        queryset_df = Forecast.objects.filter(Q(x=int(fab)) | Q(x=int("0"+x)))\
            .values_list('mas').distinct()
    
        queryset_or = Record.objects.filter(Q(pc_ext__x=int(x)) | Q(pc_ext__x=int("0"+x)))\
            .values_list('mas').distinct()
    
        new_mas_list = list(set(list(queryset_df) + list(queryset_or)))
        new_mas_list.sort()
        return self.render_json_response(dict(objects=new_mas_list))
    

Which returns a value list of masksets. How to get each value of the
valuelist(Because in my html, i have a dropdown to display each valuelist
objects, displays fine; but when I select one it returned me as a value list
object as `["5300A"]` instead of 5300A. I am using AngularJS to get the value
as follows:

    
    
    //UPDATE MAS BASED ON USER FAB
    $scope.update_mas = function(){
        $scope.processing['update_mas'] = { msg: 'loading mas..', class: 'text-warning', show: true };
        console.log('Stage1: Loading Mas..... ');
        $http.get('{% url "masresourceview"  %}', { params: { x: $scope.x} }).success(
            function(data){
                $scope.processing['update_mas'] = { msg: 'mas updated.', class: 'text-success' };
                setTimeout(function () { $scope.processing['update_mas'] = null; $scope.$apply(); }, 1000);
                $scope.maslist = data['objects'];
                $scope.isDisable = true;
                console.log($scope.maslist);
    
            }).error(function(data, status){
                $scope.processing['update_mas'] = { msg: 'Internal Error', class: 'text-danger' };
                console.log('Stage1: Internal error while loading initial data:'+status );
            });
    };
    

My resource/list looks like this:

    
    
    {
    objects: [
    [
    "AMD14NM"
    ],
    [
    "BAFFIN1"
    ],
    [
    "BAGERA1"
    ],
    [
    "ELLSMR1"
    ],
    [
    "GARFLD1"
    ],
    [
    "GARFLD2"
    ],
    

When I put `$scope.maslist = data['objects'][0];` I can get the first object's
value perfectly. What I can do for the rest of the object's values? Do I need
to improve my views.py/resources? Thanks in advance.


Answer: Just updated the return part with `flatten`.

`from compiler.ast import flatten`

`return self.render_json_response(dict(objects=flatten(new_mas_list)))`

