Django bulk update db table using model from html table Объект 'dict' не имеет атрибута

МОДЕЛЬ

class BGD(models.Model): #need to update name
    # id=models.IntegerField(primary_key=True)
    Workgroup = models.CharField(max_length=50)
    Center = models.CharField(max_length=50, blank=True, null=True)
    Description = models.CharField(max_length=250)
    InsertDate = models.DateTimeField(default=datetime.now, blank=False)
    Is_Active = models.CharField(max_length=25, blank=True, null=True)
    # def __str__(self):
    #     return "%s" % (self.id)
    class Meta:
        managed = False
        db_table="table"

View

def Control_Bidding_Groups (request):
    
    B_G_Results=BGM.objects.all()
   
    if request.method == 'POST':

        data = request.POST.dict()
        data.pop('csrfmiddlewaretoken', None)
        print('//////',data)
        for i in data.B_G_Results():
            print('???',i)
            obj = Bidding_Group_Description.objects.get(id=i[0].split("_")[1])
            print('55',obj)
            # Bidding_Group_Description.objects.filter(id=id).update(Is_Active)

            if not str(obj.Is_Active) == str(i[1]): #here check int or char datatype since 1 not equal "1"
                obj.Is_Active = i[1] 
                print(obj.Is_Active)
                obj.save()

        return render(request, "Control_Bidding_Groups.html", { "B_G_Results": B_G_Results})
    
    else:
        
        return render(request, "Control_Bidding_Groups.html", { "B_G_Results": B_G_Results}) #, "edit": edit

HTML

<section id="golf">
    <form method="POST" enctype="multipart/form-data">
        {% csrf_token %}
        <div class="mainbg padding-all-zero">
            <div class="row panelBg">

                <label class="parav" for="ddlSubmit">
                    <button class="btn btn-danger" value="Insert Records"> <span class="glyphicon glyphicon-upload"
                            style="margin-right:5px;"></span>Submit</button>
                </label>

                <table class="table table-striped" width="100%">

                    <thead>
                        <tr>
                            <th>Workgroup</th>
                            <th>Center</th>
                            <th>Bidding Group Description</th>
                            <th style="text-align:left;">Is Active</th>

                            <th>Is Active</th>

                        </tr>
                    </thead>
                    <tbody class="ui-sortable">

                        {% for d in B_G_Results%}
                        <tr>
                          
                            <td>{{d.Workgroup}}</td>
                            <td>{{d.Center}}</td>
                            <td>{{d.Description}}</td>
                            <td>{{d.Is_Active}}</td>
                            <td><input type="text" value="{{d.Is_Active}}" name="d_{{d.id}}"> </td>
                         </tr>
                            {% endfor %}
                    </tbody>
                </table>

            </div>
        </div>
    </form>
</section>

ERROR
. Объект 'dict' не имеет атрибута 'B_G_Results'

data
{'17': '17', '18': '18', '19': '19', '74': '74', '75': '75', '76': '76', '77': '77', '78': '78', '79': '79', '80': '80', '81': '81', '82': '82', '83': '83', '84': '84', '85': '85', '86': '86', '87': '87', '88': '88', '89': '89', 'Yes, NO': 'Yes, NO', 'd_17': 'активный', 'd_18': 'деактивный', 'd_19': 'деактивный', 'd_74': 'деактивный', 'd_75': 'активный', 'd_76': 'активный', 'd_77': 'off', 'd_78': 'off', 'd_79': 'off', 'd_80': 'выключено', 'd_81': 'off', 'd_82': 'off', 'd_83': 'off', 'd_84': 'off', 'd_85': 'off', 'd_86': 'off', 'd_87': 'off', 'd_88': 'off', 'd_89': 'on', 'off': 'off', 'on': 'on'}

B_G_Results=BGM.objects.all(), но ваша модель называется class BGD(models.Model)?

Вернуться на верх