Django rest framework实践记录(五)

释放双眼,带上耳机,听听看~!

改变inline显示的数量

设置extra 就可以改变inline数量

class InlineModelAdmin(BaseModelAdmin):
    """
    Options for inline editing of ``model`` instances.

    Provide ``fk_name`` to specify the attribute name of the ``ForeignKey``
    from ``model`` to its parent. This is required if ``model`` has more than
    one ``ForeignKey`` to its parent.
    """
    model = None
    fk_name = None
    formset = BaseInlineFormSet
    extra = 1
    min_num = None
    max_num = None
    template = None
    verbose_name = None
    verbose_name_plural = None
    can_delete = True
    show_change_link = False
    checks_class = InlineModelAdminChecks
    classes = None

更新指定或部分数据

class AccountUserSerializer(serializers.ModelSerializer):
    class Meta:
        model = AccountUser
        fields = ('name','mobile','province',)
class AccountUserSerializer(serializers.ModelSerializer):
    class Meta:
        model = AccountUser
        fields = ('name','mobile','province','city','country','detail','zone','the_index')

AccountUserSerializer只能更新’name’,’mobile’,’province’,即使传递了其他数据也不能更新,所以在显示的时候只会显示’name’,’mobile’,’province’。在更新和创建的时候也只会更新创建’name’,’mobile’,’province’。如果想要显示的字段和先要创建更新的字段不一样就要注意了。
Django rest framework实践记录(五)

【转自慕课】https://www.imooc.com

Python

Python虚拟环境之virtualenvwrapper vs Pipenv

2022-3-3 7:08:51

Python

[硕.Love Python] 不重复的3位数

2022-3-3 7:15:14

搜索