继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

Django rest framework实践记录(五)

无无法师
关注TA
已关注
手记 44
粉丝 54
获赞 130
改变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'。如果想要显示的字段和先要创建更新的字段不一样就要注意了。
前后对比

打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP