小编Esi*_*ngs的帖子

与仅在 django 中更新相同值更新相比,使用bulk_update 是否有任何性能优势?

我有下面的代码

Subscription.objects.filter(id__in=[subscription.id for subscription in subscriptions]).update(renewal_notification_sent=True)
Run Code Online (Sandbox Code Playgroud)

但我想知道是否有类似的事情

updatable_subscriptions = []
subs = Subscription.objects.filter(id__in=[subscription.id for subscription in subscriptions])
for sub in subs:
    sub.renewal_notification_sent = True

updatable_subscriptions.append(
    subs
)

# then
Subscription.objects.bulk_update(updatable_subscriptions, ["renewal_notification_sent"])
Run Code Online (Sandbox Code Playgroud)

会有任何性能优势。filter调用后是否会update进行 2 次数据库查询?

django django-models django-rest-framework

6
推荐指数
1
解决办法
1342
查看次数

令人困惑的术语清洁架构中的交互者

根据干净的架构,设计Interactor是包含所有业务逻辑的部分.Interactor一词对我来说很困惑.在我看来,Interactor喜欢在数据和演示者这两个不同的层之间进行交互.

这是正确的术语吗?任何人都可以清楚Interactor的目的吗?它遵循哪种模式?如果Interactor不像我看来那么层层交互的设计模式是什么?

android design-patterns architectural-patterns

5
推荐指数
3
解决办法
3597
查看次数

为什么在React-Router中使用Link组件而不是锚标记?

我是react-router的新手,我知道该Link组件将转换为Anchor标签。所以我的问题是,两者之间的真正区别是什么?

reactjs react-router redux-form

5
推荐指数
0
解决办法
3853
查看次数

Jinja2 模板将变量评估为属性

我正在为数据库编辑应用程序开发一个 Jinja2 模板,并且我正在尝试使其“可扩展” - 而不是对编辑页面进行硬编码,我正在传递我想要的属性列表表,并使用 for 循环来迭代它们。它的工作原理除了一件事之外 - 在硬编码版本中,我使用正在传递的对象的属性来查看该值是否已设置(它们都是布尔值),但我不知道如何让 jinja2 接受“能力”并将其用作“学生”对象的属性;我会在Python中使用“eval”,但不知道如何让它工作。这是代码的一个想法:

{%  for capability in capability_list %}
    <tr>
        <td>{{ capability }}</td>
        <td>
            {% if pupil.capability %}
                <img src="{{request.static_url('gdpr_permissions:static/tick.png')}}" width="25">
            {% else %}
                <img src="{{request.static_url('gdpr_permissions:static/cross.png')}}" width="25">
            {% endif %}
        </td>
        <td>
            <div class="onoffswitch">
                <input type="checkbox" name="{{ capability }}" class="onoffswitch-checkbox" value ='No' id="{{ capability }}" checked>
                    <label class="onoffswitch-label" for="{{ capability }}">
                    <span class="onoffswitch-inner"></span>
                    <span class="onoffswitch-switch"></span>
                    </label>
            </div>
        </td>
    </tr>
    {% endfor %}
Run Code Online (Sandbox Code Playgroud)

这是{% if pupil.capability %}不起作用的部分 - 我希望它成为(比如说)pupil.web_access等 …

eval jinja2 python-3.x

4
推荐指数
1
解决办法
4318
查看次数

python 3.8 上的 gsheet batch_update 是否存在问题?

按照以下问题和解决方案,如何使用 python gspreadsheet 重置所有行和列数据,我有以下确切的代码

requests = {"requests": [{"updateCells": {"range": {"sheetId": worksheet._properties['sheetId']}, "fields": "*"}}]}
res = spreadsheet.batch_update(requests)
Run Code Online (Sandbox Code Playgroud)

但我收到以下错误

File "/root/.local/lib/python3.8/site-packages/gspread/models.py", line 1171, in batch_update data = [ File "/root/.local/lib/python3.8/site-packages/gspread/models.py", line 1172, in <listcomp> dict(vr, range=absolute_range_name(self.title, vr['range'])) TypeError: string indices must be integers
Run Code Online (Sandbox Code Playgroud)

有谁有过这样的经历吗?你是如何解决的?

python google-sheets python-3.x gspread google-sheets-api

3
推荐指数
1
解决办法
962
查看次数

在jQuery append方法内添加for循环

我有一个大多数元素都是静态的表,但是我<tr></tr>想使用for循环动态更改它,我只能添加一个for循环来更新表中的所有内容。

for(var x = 0; x< foo.length; x++){//Move the for loop from here
$("div#show_details").append('<table class="'+receipt_no+'" id="print_me" style="background:#ffffff;width:800px;font-family:Roboto;text-align:center;">',
    '<tbody>',
    '<tr><td colspan="3"><h4 style="font-size:20px;color:#009688;text-align:center">Thank you Student Name,</h4></td></tr>',
    '<tr><td colspan="3">Your order for receipt no: <b>'+receipt_no+'</b> has the following items.</td></tr>',
    '<tr><td td colspan="3"></td></tr>',
    '<tr><td>#</td><td style="text-align:left">Item</td><td>Price</td></tr>',
    //I want to use a for loop inside here

    '<tr><td>'+foo[x].foodCount+'</td><td style="text-align:left">'+foo[x].foodName+'</td><td>'+foo[x].price+'</td></tr>',
    '<tr style="font-weight:bold"><td colspan="2" style="text-align:left">Total</td><td>'+foo[0].price*foo[0].foodCount+'</td></tr>',
    '</tbody>',
    '</table>',
    '<a class="btn btn-xs btn-info" href="javascript:void(processPrint());">Print</a>'
    );
    }
Run Code Online (Sandbox Code Playgroud)

我无法在append方法内部添加for循环以确保仅<tr><td>'+foo[x].foodCount+'</td><td style="text-align:left">'+foo[x].foodName+'</td><td>'+foo[x].price+'</td></tr>',更改的内容 。任何帮助将不胜感激。

html javascript jquery

2
推荐指数
1
解决办法
1368
查看次数

测试在对象初始化 Python 期间是否调用了某个方法

我有一个超类,它在初始化期间调用某个独立的方法。就像是

class MasterClass:
    def __init__(self, *args, **kwargs):
        if type(self).__name__ == "SpecificClass":
            call_a_module_method()
Run Code Online (Sandbox Code Playgroud)

我想测试调用这个类的子类SpecificClass是否会call_a_module_method调用方法。

python django unit-testing python-3.x python-unittest

0
推荐指数
1
解决办法
236
查看次数