def addon_edit(request, pk): instance = get_object_or_404(Addon, pk=pk) if instance.category.container.owner != request.user: raise Http404("not allowed") form = AddAddonForm( request.POST or None, instance=instance, request=request, initial={ 'container': instance.list.container.pk } ) if request.method == 'POST': if form.is_valid(): form.save() return { 'redirect': 'catalog:addon-list', 'redirect-args': (form.cleaned_data['container'].pk,) } return {'form': form}
def addon_add(request, pk=None): container = get_object_or_None(Container, pk=pk) if container.owner != request.user: raise Http404("not allowed") form = AddAddonForm( request.POST or None, request=request, initial={ 'container': container } ) if request.method == 'POST': if form.is_valid(): form.save() return { 'redirect': 'catalog:addon-list', 'redirect-args': (form.cleaned_data['container'].pk,) } return {'form': form}