小编Bre*_*t81的帖子

Django管理员改变表单加载速度很慢

我的一个Django网站有以下数据库模型:在Django App中"常见":

class Collection(models.Model):
    name = models.CharField(max_length = 255, unique = True)
    _short_name = models.CharField(db_column="short_name", max_length = 32, blank=True)

class Particle(models.Model):
    content = models.TextField(blank=False)
    owner = models.ForeignKey(Collection)
    order = models.IntegerField(null=True, blank=True)
Run Code Online (Sandbox Code Playgroud)

在Django App"情景喜剧"中:

class Media(models.Model):
    name = models.CharField(max_length = 248)
    _short_name = models.CharField(db_column="short_name", max_length = 32, blank=True)
    capital = models.CharField(max_length = 1)
    description = models.TextField(blank=True)
    progress = models.CharField(max_length = 32, blank=True, null=True)

class Relation(models.Model):
    name = models.CharField(max_length = 128)
    _short_name = models.CharField(db_column="short_name", max_length = 32, blank=True)
    description = models.TextField(blank=True)
    parent …
Run Code Online (Sandbox Code Playgroud)

python django performance django-models django-admin

12
推荐指数
3
解决办法
6747
查看次数

QT quick2 qml动态更改GridView列

我使用GridView来显示ListModel.最初我将cellWidth设置为:

cellWidth = grid.width/3

创建一个3列网格.然后我想将列数更改为2,所以我将cellWidth设置为:

cellWidth = grid.width/2
Run Code Online (Sandbox Code Playgroud)

GridView的显示改变了.但是,当我调整容器的桌面窗口大小时,gridview中的单元格将不再更改大小.

我该怎么做才能使它正确?

请看下面的代码:

import QtQuick 2.1
import QtQuick.Controls 1.0
import QtQuick.Window 2.0

ApplicationWindow {
title: qsTr("Hello World")
width: 640
height: 480

menuBar: MenuBar {
    Menu {
        title: qsTr("File")
        MenuItem {
            text: qsTr("2 columns")
            onTriggered: grid.cellWidth = grid.width/2;
        }
        MenuItem {
            text: qsTr("3 columns")
            onTriggered: grid.cellWidth = grid.width/3;
        }
    }
}

GridView {
    id: grid
    anchors.fill: parent
    cellWidth: width / 3;
    cellHeight: 300;
    model: ListModel {
        ListElement {
            name: "Apple"
            cost: 2.45
        } …
Run Code Online (Sandbox Code Playgroud)

c++ qml qtquick2

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

如何在QtQuick 2中对QML TableView进行排序?

我想用Qt 5.1实现一个带有自定义角色的可排序TableView.但是,当用户点击标题时,我不知道该怎么做才能对它进行排序.

在我的Qt .pro文件中,我补充说:

!android: !ios: !blackberry: qtHaveModule(widgets): QT += widgets
Run Code Online (Sandbox Code Playgroud)

在main.cpp中,我用作QtWidgets/QApplication全局app实例,并使用qmlRegisterType作为我的新模型类(见下文):

qmlRegisterType<PositionModel>("MyDataModule", 1, 0, "PositionModel");
Run Code Online (Sandbox Code Playgroud)

PositionModel声明如下:

class PositionModel : public QAbstractTableModel
{
    Q_OBJECT
public:
    enum PositionRoles {
        CustomRol1 = Qt::UserRole + 1,
        CustomRow2,
        PositionRoleMaxPlus1
    };

    explicit PositionModel(QObject *parent = 0);

    int rowCount(const QModelIndex &parent = QModelIndex()) const;
    int columnCount(const QModelIndex &parent = QModelIndex()) const;

    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
    QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;

    bool setData(const QModelIndex &index, …
Run Code Online (Sandbox Code Playgroud)

c++ qt qml qtquick2 qtquickcontrols

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

调用重载运算符 - >在编译时解决了吗?

当我尝试编译代码时:(注意:func和func2不是拼写错误)

struct S
{
    void func2() {}
};

class O
{
public:
    inline S* operator->() const;
private:
    S* ses;
};

inline S* O::operator->() const
{
    return ses;
}

int main()
{
    O object;
    object->func();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

报告编译错误:

D:\code>g++ operatorp.cpp -S -o operatorp.exe
operatorp.cpp: In function `int main()':
operatorp.cpp:27: error: 'struct S' has no member named 'func'
Run Code Online (Sandbox Code Playgroud)

看来调用"operator->"的重载函数是在编译期间完成的吗?我添加了"-S"选项仅用于编译.

c++ operator-overloading

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

为什么由编译器决定在为变量赋予超出范围值时要分配的值

在C++ Primer第4版2.1.1中,它说"在为签名类型分配超出范围的值时,由编译器来决定分配什么值".

我无法理解.我的意思是,如果您有"char 5 = 299"之类的代码,编译器将生成asm代码,如" mov BYTE PTR _sc$[ebp], 43"(VC)或" movb $43, -2(%ebp)"(gcc + mingw),它由编译器决定.

但是如果我们分配一个由用户输入给出的值呢?比如,通过命令行?生成的asm代码将是" movb %al, -1(%ebp)"(gcc + mingw)和"

mov cl, BYTE PTR _i$[ebp]
mov BYTE PTR _sc$[ebp], cl
Run Code Online (Sandbox Code Playgroud)

"(VC),那么现在编译器如何决定会发生什么?我想现在它是由CPU决定的.

你能给我一个明确的解释吗?

c c++ compiler-construction assembly

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