小编bri*_*ian的帖子

在Django 1.8中创建多个没有多次匹配到db的对象

使用Django 1.8,如何在单个db事务中创建多个对象并写入db?

似乎以前的版本有@commit_manually.但是当我尝试修改此代码时:https://stackoverflow.com/a/29834940我得到一个例外

django.db.transaction.TransactionManagementError: The outermost 'atomic' block cannot use savepoint = False when autocommit is off.
Run Code Online (Sandbox Code Playgroud)

在我看过很多帖子中说要用"with transaction.atomic()"块包装,但这会在每个循环中击中db.

这是我的代码的简化版本.我没有运行它,但它应该显示我正在尝试做什么.

class Foo(models.Model):
    Name = models.CharField( max_length=200 )

class Bar(models.Model):
    Foos = models.ManyToManyField( foo )

class Processor(object):
    def run(self,):
        myBar = Bar.object.create()

        myList = ['a', 'b', 'c', 'd']

        if True:
            set_autocommit( False )

            for char in myList:
                myFoo = Foo.objects.create(Name=char)
                myBar.Foos.add( myFoo )

            commit()
            set_autocommit( True )
Run Code Online (Sandbox Code Playgroud)

我正在尝试进行所有这些更改,只打了一次db.我知道有model.objects.bulk_create,但我找不到处理m2m关系的方法.另外bulk_create不会返回db实例,因此我必须将它们从m2中拉出来以获取m2m关系.

database django transactions atomicity

10
推荐指数
1
解决办法
6457
查看次数

"错误:OpenGLES初始化失败!" 在CentOS上使用android SKD

当我跑: /usr/local/android-sdk-linux/tools/emulator -avd tst

我收到错误:

Failed to open lib64EGL_translator
Failed to init_egl_dispatch
emulator: ERROR: OpenGLES initialization failed!
emulator: ERROR: OpenGLES emulation library could not be initialized!
emulator: WARNING: Could not initialize OpenglES emulation, using software renderer.
emulator: emulator window was out of view and was recentered
Run Code Online (Sandbox Code Playgroud)

我按照这里的步骤进行了操作:http://www.redips.net/android/emulator-fedora-linux/

我也尝试过使用命令emulator-arm和emulator64-arm

我尝试的另一件事是

export LD_LIBRARY_PATH=/usr/local/android-sdk-linux/tools/lib:$LD_LIBRARY_PATH
Run Code Online (Sandbox Code Playgroud)

另一个尝试是参数:

-no-audio -gpu off
Run Code Online (Sandbox Code Playgroud)

我正在使用全新安装的CentOS 6.6并运行yum update.我正在使用android SDK:http://dl.google.com/android/android-sdk_r23.0.2-linux.tgz

我运行/ usr/local/android-sdk-linux/tools/android并安装了Android 5.0 api + arm.我再次尝试使用Android 4.4 AVM.

我已经尝试了所有可以找到的建议.还有其他建议吗?

android

7
推荐指数
1
解决办法
2216
查看次数

计算Python中的直方图峰

在Python中,如何计算直方图的峰值?

我尝试了这个:

import numpy as np
from scipy.signal import argrelextrema

data = [0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 1, 2, 3, 4,

        5, 6, 7, 8, 9, 5, 6, 7, 8, 9, 5, 6, 7, 8, 9,

        12,

        15, 16, 17, 18, 19, 15, 16, 17, 18, 

        19, 20, 21, 22, 23, 24,]

h = np.histogram(data, bins=[0, 5, 10, 15, 20, 25])
hData = h[0]
peaks = argrelextrema(hData, np.greater)
Run Code Online (Sandbox Code Playgroud)

但是结果是:

(array([3]),) …
Run Code Online (Sandbox Code Playgroud)

python

6
推荐指数
3
解决办法
8115
查看次数

CSS粗体不起作用

对于下面的代码,粗体不起作用.如果我发表评论,font:inherit;那么它按预期工作.

我不明白为什么会这样.我以为<p>会继承<body>而且大胆会起作用.我在Firefox,IE,Safari和Opera中看到了完全相同的东西.

我错过了什么?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <link href='http://fonts.googleapis.com/css?family=Droid+Sans:400,700,bold' rel='stylesheet' type='text/css' />

        <style type="text/css">
            html, body, div, span, applet, object, iframe,
            h1, h2, h3, h4, h5, h6, p, blockquote, pre,
            a, abbr, acronym, address, big, cite, code,
            del, dfn, em, img, ins, kbd, q, s, samp,
            small, strike, strong, sub, sup, tt, var,
            b, u, i, center,
            dl, dt, dd, …
Run Code Online (Sandbox Code Playgroud)

css

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

标签 统计

android ×1

atomicity ×1

css ×1

database ×1

django ×1

python ×1

transactions ×1