please share your related models and form as well.

On Wed, Jun 23, 2021 at 1:22 AM David Crandell <[email protected]>
wrote:

> 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 <[email protected]>[email protected]
> [email protected]
> [email protected]
>
> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAACv6dMBaATx9V%3D0t6qrZk2WPVtcVGCOvXwW-aHurzxGE9PB%3Dw%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAACv6dMBaATx9V%3D0t6qrZk2WPVtcVGCOvXwW-aHurzxGE9PB%3Dw%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAKPY9p%3DSPsGj1sMuY4dutV8Gau7H0qEztgRNbKVNzLFGxiK4pw%40mail.gmail.com.

Reply via email to