Exemplo n.º 1
0
    def post(self, request, pk=None) :
        form = CreateForm(request.POST, request.FILES or None)

        if not form.is_valid() :
            ctx = {'form' : form}
            return render(request, self.template, ctx)

        # Add developer to the model before saving
        instance = form.save(commit=False)
        developer = get_object_or_404(Developer, developer_account=request.user)
        instance.developer = developer
        instance.save()
        for language in form.cleaned_data['language']:
            App_to_language.objects.create(app=instance, language=language)
        return redirect(self.success_url)
Exemplo n.º 2
0
    def post(self, request, pk=None) :
        developer = get_object_or_404(Developer, developer_account=request.user)
        app = get_object_or_404(App, app_id=pk, developer=developer)
        form = CreateForm(request.POST, request.FILES or None, instance=app)

        if not form.is_valid() :
            ctx = {'form' : form}
            return render(request, self.template, ctx)

        app = form.save(commit=False)
        app.save()
        app_lan_deletes = get_list_or_404(App_to_language, app=app)
        for app_lan_delete in app_lan_deletes:
            app_lan_delete.delete()
        for language in form.cleaned_data['language']:
            App_to_language.objects.create(app=app, language=language)

        return redirect(self.success_url)