Hello, I come from a platform where I built out forms and then manually
wrote insert statements from the form input entering all the data at once.

What I want to do is enter a customer (one table), have it populate a
master region with the same name (another table), then fill out a master
location record (another table) and then create a user from the person
profiled in the customer information (another table)

I'm trying to go to the next page which is a location form and pass the
value of the customer ID to the region form included on the same page.

  There has to be a better way to do this. I still have no idea how to
combine and enter information into multiple models from one form. The ORM
is cool but it seems so limited. I guess I just don't understand it.

class CustomerCreateView(View):
    template_name = 'ohnet/customer_form.html'
    form_class = CustomerForm
    rform = RegionWCust

    def get(self, request, *args, **kwargs):
        form = self.form_class
        rform = self.rform
        return render(request, self.template_name, {'form': form,
'rform': rform})

    def post(self, request, *args, **kwargs):
        form = self.form_class(request.POST, request.FILES)
        rform = self.rform(request.POST)
        if form.is_valid() and rform.is_valid():
            form.save()
            obj = Customers.objects.latest('id')
            f = rform.save(commit=False)
            f.customer_id = obj
            f.save()
            messages.success(request, f'Customer entered successfully')
            return redirect('ohnet:custlocs-new', obj)


David L. Crandell
469-585-5009
g <da...@onholdwizard.com>uitard...@outlook.com
guitardave8...@gmail.com
da...@onholdwizard.com

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAACv6dMBaATx9V%3D0t6qrZk2WPVtcVGCOvXwW-aHurzxGE9PB%3Dw%40mail.gmail.com.

Reply via email to