Skip to main content

class RoutingForAniGroupUpdate(UpdateView):

    model = RoutingForAniGroup
    template_name = 'forms.html'
    success_url = reverse_lazy('routing:ani')
    success_message = "%(name)s was created successfully"
    form_class = RoutingForAniGroupForm
    object = None

    def get(self, request, *args, **kwargs):
        self.object = self.get_object()
        form_class = self.get_form_class()
        form = self.get_form(form_class)

        # Formset
        formset = modelformset_factory(RoutingForAni, form=RoutingForAniForm, can_delete=True, extra=4)

        # formset.form = staticmethod(curry(RoutingForAniForm, user=self.request.user))
        query = self.object.routingforani_set.filter().order_by("id")[0:1]

        print("\n*****************\n**************\n",query.count())

        eventdate_formset = formset(queryset=query)
        #print(eventdate_formset)
        print(self.get_context_data)

        return self.render_to_response(
            self.get_context_data(form=form, eventdate_formset=eventdate_formset)
        )

    def post(self, request, *args, **kwargs):
        self.object = self.get_object()
        form_class = self.get_form_class()
        form = self.get_form(form_class)

        # Formset
        formset = modelformset_factory(RoutingForAni, form=RoutingForAniForm, can_delete=True, extra=4)
        # formset.form = staticmethod(curry(RoutingForAniForm, user=self.request.user))
        eventdate_formset = formset(
            self.request.POST,
            queryset=self.object.routingforani_set.all()
        )

        if form.is_valid() and eventdate_formset.is_valid():
            return self.form_valid(form, eventdate_formset)
        return self.form_invalid(form, eventdate_formset)

    def form_invalid(self, form, eventdate_formset):
        messages.error(self.request, "Invalid form data")
#        print(form, eventdate_formset)
        return self.render_to_response(
            self.get_context_data(form=form, eventdate_formset=eventdate_formset)
        )

    def form_valid(self, form, eventdate_formset):
        response = super(RoutingForAniGroupUpdate, self).form_valid(form)
        instances = eventdate_formset.save(commit=False)

        for obj in eventdate_formset.deleted_objects:
            obj.delete()

        for obj in instances:
            obj.group_id = self.object.pk
            obj.save()

        messages.success(self.request, "Update ")
        return response

class RoutingForAniGroupUpdate(UpdateView):

    model = RoutingForAniGroup
    template_name = 'forms.html'
    success_url = reverse_lazy('routing:ani')
    success_message = "%(name)s was created successfully"
    form_class = RoutingForAniGroupForm
    object = None

    def get(self, request, *args, **kwargs):
        self.object = self.get_object()
        form_class = self.get_form_class()
        form = self.get_form(form_class)

        # Formset
        formset = modelformset_factory(RoutingForAni, form=RoutingForAniForm, can_delete=True, extra=4)

        # formset.form = staticmethod(curry(RoutingForAniForm, user=self.request.user))
        query = self.object.routingforani_set.filter().order_by("id")[0:1]

        print("\n*****************\n**************\n",query.count())

        eventdate_formset = formset(queryset=query)
        #print(eventdate_formset)
        print(self.get_context_data)

        return self.render_to_response(
            self.get_context_data(form=form, eventdate_formset=eventdate_formset)
        )

    def post(self, request, *args, **kwargs):
        self.object = self.get_object()
        form_class = self.get_form_class()
        form = self.get_form(form_class)

        # Formset
        formset = modelformset_factory(RoutingForAni, form=RoutingForAniForm, can_delete=True, extra=4)
        # formset.form = staticmethod(curry(RoutingForAniForm, user=self.request.user))
        eventdate_formset = formset(
            self.request.POST,
            queryset=self.object.routingforani_set.all()
        )

        if form.is_valid() and eventdate_formset.is_valid():
            return self.form_valid(form, eventdate_formset)
        return self.form_invalid(form, eventdate_formset)

    def form_invalid(self, form, eventdate_formset):
        messages.error(self.request, "Invalid form data")
#        print(form, eventdate_formset)
        return self.render_to_response(
            self.get_context_data(form=form, eventdate_formset=eventdate_formset)
        )

    def form_valid(self, form, eventdate_formset):
        response = super(RoutingForAniGroupUpdate, self).form_valid(form)
        instances = eventdate_formset.save(commit=False)

        for obj in eventdate_formset.deleted_objects:
            obj.delete()

        for obj in instances:
            obj.group_id = self.object.pk
            obj.save()

        messages.success(self.request, "Update ")
        return response

class RoutingForAniGroupUpdate(UpdateView):

    model = RoutingForAniGroup
    template_name = 'forms.html'
    success_url = reverse_lazy('routing:ani')
    success_message = "%(name)s was created successfully"
    form_class = RoutingForAniGroupForm
    object = None

    def get(self, request, *args, **kwargs):
        self.object = self.get_object()
        form_class = self.get_form_class()
        form = self.get_form(form_class)

        # Formset
        formset = modelformset_factory(RoutingForAni, form=RoutingForAniForm, can_delete=True, extra=4)

        # formset.form = staticmethod(curry(RoutingForAniForm, user=self.request.user))
        query = self.object.routingforani_set.filter().order_by("id")[0:1]

        print("\n*****************\n**************\n",query.count())

        eventdate_formset = formset(queryset=query)
        #print(eventdate_formset)
        print(self.get_context_data)

        return self.render_to_response(
            self.get_context_data(form=form, eventdate_formset=eventdate_formset)
        )

    def post(self, request, *args, **kwargs):
        self.object = self.get_object()
        form_class = self.get_form_class()
        form = self.get_form(form_class)

        # Formset
        formset = modelformset_factory(RoutingForAni, form=RoutingForAniForm, can_delete=True, extra=4)
        # formset.form = staticmethod(curry(RoutingForAniForm, user=self.request.user))
        eventdate_formset = formset(
            self.request.POST,
            queryset=self.object.routingforani_set.all()
        )

        if form.is_valid() and eventdate_formset.is_valid():
            return self.form_valid(form, eventdate_formset)
        return self.form_invalid(form, eventdate_formset)

    def form_invalid(self, form, eventdate_formset):
        messages.error(self.request, "Invalid form data")
#        print(form, eventdate_formset)
        return self.render_to_response(
            self.get_context_data(form=form, eventdate_formset=eventdate_formset)
        )

    def form_valid(self, form, eventdate_formset):
        response = super(RoutingForAniGroupUpdate, self).form_valid(form)
        instances = eventdate_formset.save(commit=False)

        for obj in eventdate_formset.deleted_objects:
            obj.delete()

        for obj in instances:
            obj.group_id = self.object.pk
            obj.save()

        messages.success(self.request, "Update ")
        return response

class RoutingForAniGroupUpdate(UpdateView):

    model = RoutingForAniGroup
    template_name = 'forms.html'
    success_url = reverse_lazy('routing:ani')
    success_message = "%(name)s was created successfully"
    form_class = RoutingForAniGroupForm
    object = None

    def get(self, request, *args, **kwargs):
        self.object = self.get_object()
        form_class = self.get_form_class()
        form = self.get_form(form_class)

        # Formset
        formset = modelformset_factory(RoutingForAni, form=RoutingForAniForm, can_delete=True, extra=4)

        # formset.form = staticmethod(curry(RoutingForAniForm, user=self.request.user))
        query = self.object.routingforani_set.filter().order_by("id")[0:1]

        print("\n*****************\n**************\n",query.count())

        eventdate_formset = formset(queryset=query)
        #print(eventdate_formset)
        print(self.get_context_data)

        return self.render_to_response(
            self.get_context_data(form=form, eventdate_formset=eventdate_formset)
        )

    def post(self, request, *args, **kwargs):
        self.object = self.get_object()
        form_class = self.get_form_class()
        form = self.get_form(form_class)

        # Formset
        formset = modelformset_factory(RoutingForAni, form=RoutingForAniForm, can_delete=True, extra=4)
        # formset.form = staticmethod(curry(RoutingForAniForm, user=self.request.user))
        eventdate_formset = formset(
            self.request.POST,
            queryset=self.object.routingforani_set.all()
        )

        if form.is_valid() and eventdate_formset.is_valid():
            return self.form_valid(form, eventdate_formset)
        return self.form_invalid(form, eventdate_formset)

    def form_invalid(self, form, eventdate_formset):
        messages.error(self.request, "Invalid form data")
#        print(form, eventdate_formset)
        return self.render_to_response(
            self.get_context_data(form=form, eventdate_formset=eventdate_formset)
        )

    def form_valid(self, form, eventdate_formset):
        response = super(RoutingForAniGroupUpdate, self).form_valid(form)
        instances = eventdate_formset.save(commit=False)

        for obj in eventdate_formset.deleted_objects:
            obj.delete()

        for obj in instances:
            obj.group_id = self.object.pk
            obj.save()

        messages.success(self.request, "Update ")
        return response
Origen Enlace
NEFEGAGO
  • 448
  • 8
  • 21

UpdateView django

Hola quisiera saber si puedo paginar un UpdateView de django como lo puedo realizar tengo el siguiente codigo pero no se como puedo paginarlo

class RoutingForAniGroupUpdate(UpdateView):

    model = RoutingForAniGroup
    template_name = 'forms.html'
    success_url = reverse_lazy('routing:ani')
    success_message = "%(name)s was created successfully"
    form_class = RoutingForAniGroupForm
    object = None

    def get(self, request, *args, **kwargs):
        self.object = self.get_object()
        form_class = self.get_form_class()
        form = self.get_form(form_class)

        # Formset
        formset = modelformset_factory(RoutingForAni, form=RoutingForAniForm, can_delete=True, extra=4)

        # formset.form = staticmethod(curry(RoutingForAniForm, user=self.request.user))
        query = self.object.routingforani_set.filter().order_by("id")[0:1]

        print("\n*****************\n**************\n",query.count())

        eventdate_formset = formset(queryset=query)
        #print(eventdate_formset)
        print(self.get_context_data)

        return self.render_to_response(
            self.get_context_data(form=form, eventdate_formset=eventdate_formset)
        )

    def post(self, request, *args, **kwargs):
        self.object = self.get_object()
        form_class = self.get_form_class()
        form = self.get_form(form_class)

        # Formset
        formset = modelformset_factory(RoutingForAni, form=RoutingForAniForm, can_delete=True, extra=4)
        # formset.form = staticmethod(curry(RoutingForAniForm, user=self.request.user))
        eventdate_formset = formset(
            self.request.POST,
            queryset=self.object.routingforani_set.all()
        )

        if form.is_valid() and eventdate_formset.is_valid():
            return self.form_valid(form, eventdate_formset)
        return self.form_invalid(form, eventdate_formset)

    def form_invalid(self, form, eventdate_formset):
        messages.error(self.request, "Invalid form data")
#        print(form, eventdate_formset)
        return self.render_to_response(
            self.get_context_data(form=form, eventdate_formset=eventdate_formset)
        )

    def form_valid(self, form, eventdate_formset):
        response = super(RoutingForAniGroupUpdate, self).form_valid(form)
        instances = eventdate_formset.save(commit=False)

        for obj in eventdate_formset.deleted_objects:
            obj.delete()

        for obj in instances:
            obj.group_id = self.object.pk
            obj.save()

        messages.success(self.request, "Update ")
        return response