小编Lar*_*ara的帖子

Django嵌套事务 - "with transaction.atomic()"

我想知道我是否有这样的事情:

def functionA():
    with transaction.atomic():
        #save something
        functionB()

def functionB():
    with transaction.atomic():
        #save another thing
Run Code Online (Sandbox Code Playgroud)

有人知道会发生什么吗?如果functionB失败,functionA也会回滚吗?

谢谢!

django transactions nested atomic

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

Django聚合 - 表达式包含混合类型.您必须设置output_field

我正在尝试实现聚合查询,这是我的代码:

TicketGroup.objects.filter(event=event).aggregate(
                           total_group=Sum(F('total_sold')*F('final_price')))
Run Code Online (Sandbox Code Playgroud)

我在TicketGroup对象中有'total_sold'和'final_price',我想要做的就是求和并乘以值来得到所有TicketGroup的总销售额.

我得到的只是这个错误:

表达式包含混合类型.您必须设置output_field

我做错了什么,因为我把'total_group'称为我的输出字段?

谢谢!

django aggregate-functions django-orm django-queryset

14
推荐指数
2
解决办法
8859
查看次数

Django - 更改字段验证消息

我的新闻稿表单中有一个电子邮件字段,如下所示:

class NewsletterForm(forms.ModelForm):

    email = forms.EmailField(widget=forms.EmailInput(attrs={
        'autocomplete': 'off',
        'class': 'form-control',
        'placeholder': _('seuemail@email.com'),
        'required': 'required'
    }))

    class Meta:
        model = Newsletter
        fields = ['email', ]
Run Code Online (Sandbox Code Playgroud)

我的表单正在运行,但是当我输入"ahasudah @ ahs"没有域名的DOT时,我收到此错误"输入有效的电子邮件地址"

这是哪里?

我刚刚检查了原始源代码,但我找不到像其他字段一样覆盖的错误消息.

https://github.com/django/django/blob/master/django/forms/fields.py#L523

任何想法如何覆盖此消息?

python django django-forms

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

键盘在使用adjustPan时隐藏操作栏

我有一个"混合"的聊天,editText和发送按钮是java/native,我的聊天系统在服务器中,我将它加载到webview中.

当用户开始输入时,我想用键盘调整我的webview.我使用了adjustPan并且工作正常,但现在我的操作栏在键盘打开时隐藏了.

这是我的Activity的Android清单的一部分:

    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
        android:windowSoftInputMode="adjustPan">
    </activity>
Run Code Online (Sandbox Code Playgroud)

这是我的chat.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<WebView
    android:id="@+id/webview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentTop="true"
    android:layout_above="@+id/llFooter">
</WebView>

<LinearLayout
    android:id="@id/llFooter"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:orientation="horizontal">

    <EditText
        android:id="@+id/chat_message"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="0.9"
        android:maxLines="3"
        android:hint="Schreibe deine Nachricht hier..">
    </EditText>

    <Button
        android:id="@+id/chat_button"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="0.1"
        android:text=">">
    </Button>
</LinearLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

注意:我的聊天是片段

任何人都知道如何解决它?

我已经检查了这些链接但未成功:

键盘出现时ActionBar隐藏

使用adjustPan时软键盘隐藏ActionBar

编辑1:增加了屏幕截图

AdjustPan:隐藏了操作栏,但聊天webview适合键盘AdjustResize:操作栏未隐藏,但聊天webview不合适.应该向下滚动直到最后的消息

使用AdjustPan

使用AdjustResize

android android-ui android-layout

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