views.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:planet-b-saleor 作者: planet-b 项目源码 文件源码
def update(request, site_id=None):
    site_settings = get_object_or_404(SiteSettings, pk=site_id)
    site = site_settings.site
    site_settings_form = SiteSettingForm(
        request.POST or None, instance=site_settings)
    site_form = SiteForm(request.POST or None, instance=site)
    authorization_qs = AuthorizationKey.objects.filter(
        site_settings=site_settings)
    formset = AuthorizationKeyFormSet(
        request.POST or None, queryset=authorization_qs,
        initial=[{'site_settings': site_settings}])
    if all([site_settings_form.is_valid(), site_form.is_valid(),
            formset.is_valid()]):
        site = site_form.save()
        site_settings_form.instance.site = site
        site_settings = site_settings_form.save()
        formset.save()
        messages.success(request, _('Updated site %s') % site_settings)
        return redirect('dashboard:site-update', site_id=site_settings.id)
    ctx = {'site': site_settings, 'site_settings_form': site_settings_form,
           'site_form': site_form, 'formset': formset}
    return TemplateResponse(request, 'dashboard/sites/detail.html', ctx)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号