小编Vic*_*tak的帖子

从另一个组件中的一个Vue单个组件获取数据?

我使用Vue.js 2.5.13并拥有这种结构:

component-one.vue:

<template>
  <div>
    <input type="text" v-model="input_one">
    <component-two></component-two>
  </div>
</template>

<script>
  import ComponentTwo from 'component-two.vue'

  export default {
    name: "component-one",
    components: {
      ComponentTwo
    },
    data() {
      return {
        input_one: 'Hello from ComponentOne',
        input_two: ... // <-- I want to get value from ComponentTwo input_two (v-model) here
      }
    }
  }
</script>
Run Code Online (Sandbox Code Playgroud)

component-two.vue:

<template>
  <div>
    <input type="text" v-model="input_two">
  </div>
</template>

<script>
  export default {
    name: "component-two",
    data() {
      return {
        input_one: 'Hello from ComponentTwo'
      }
    }
  } …
Run Code Online (Sandbox Code Playgroud)

vue.js vue-component vuejs2

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

Django 管理员。在日期之后禁用“list_editable”字段进行编辑?

Django 2.0.3,Python 3.6.1

我有标准的 Django 管理面板。对于我的模型之一,我创建list_editable了一些字段(providerprovider_price屏幕截图)。问题是:如何list_editable在某个日期后禁用这些字段进行编辑?

例如,如果现在是March 11, 2018和更旧,字段providerprovider_price被禁用并且不会在列表视图中编辑(仅在单个记录更改视图中)。

在此处输入图片说明

python django django-admin

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

如何在Django REST框架中将选择显示名称传递给模型序列化?

我的env是Django 2.0.3,DRF 3.8.2和Python 3.6.4.

我有一个模型serializers.py:

class TransferCostSerializer(serializers.ModelSerializer):

    def to_representation(self, instance):
        field_view = super().to_representation(instance)
        if field_view['is_active']:
            return field_view
        return None

    class Meta:
        model = TransferCost
        fields = ('id', 'destination', 'total_cost', 'is_active',)
Run Code Online (Sandbox Code Playgroud)

where destinationfield是3个元素的选择字段:

DESTINATION = (
    ('none', _('I will drive by myself')),
    ('transfer_airport', _('Only from airport')),
    ('transfer_round_trip', _('Round trip')),
)
Run Code Online (Sandbox Code Playgroud)

这是我的models.py:

class TransferCost(models.Model):

    destination = models.CharField(
        _('Transfer Destination'), choices=DESTINATION, max_length=55
    )
    total_cost = models.PositiveIntegerField(
        _('Total cost'), default=0
    )
    is_active = models.BooleanField(_('Transfer active?'), default=True)

    class Meta:
        verbose_name …
Run Code Online (Sandbox Code Playgroud)

python django django-rest-framework

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

如何使用 Pytest 在 Django 中测试缓存存储(Redis)?

我正在使用 Django 1.11.9 和django-pytest库来测试我的应用程序。另外,我使用 Redis 作为缓存存储。我的问题是 \xe2\x80\x94 如何制作测试缓存存储并在运行测试之前使用测试数据设置它?与 Django 数据库的方式类似。

\n\n

我想添加一些key: value数据来测试缓存存储(在 Redis 中),运行测试,然后删除所有这些测试数据(清除测试缓存)。

\n

django caching redis pytest pytest-django

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