Thank you for your reply.
here are my models. Forms below.
MODELS
class Customers(Prospects):
cust_id = models.IntegerField(default=0)
vertical_cat = models.IntegerField(default=0)
custom_cat = models.IntegerField(default=0)
logo = models.ImageField(default='default.png',
upload_to='media/cust-logos/')
max_scripts = models.IntegerField(default=0)
branch_custom_scripts = models.BooleanField(default=False)
receive_emails = models.BooleanField(default=True)
customer_rep_id = models.SmallIntegerField(default=0)
customer_writer_id = models.SmallIntegerField(default=0)
customer_male_vt_id = models.SmallIntegerField(default=0)
customer_fem_vt = models.SmallIntegerField(default=0)
customer_sales_rep = models.SmallIntegerField(default=0)
contract_date_first = models.DateTimeField(default=None, null=True,
blank=True)
contract_date_renewal = models.DateTimeField(default=None, null=True,
blank=True)
contract_billing_type = models.CharField(max_length=200, null=True,
blank=True)
anniversary = models.DateTimeField(default=None, null=True, blank=True)
is_on_contract = models.BooleanField(default=False)
internal_flag = models.IntegerField(default=0)
shuff_freq_pref = models.SmallIntegerField(default=0)
shuff_freq_upd = models.DateTimeField(default=None, null=True, blank=True)
shuff_freq_7 = models.BooleanField(default=True)
shuff_freq_14 = models.BooleanField(default=True)
shuff_freq_30 = models.BooleanField(default=True)
shuff_freq_60 = models.BooleanField(default=True)
shuff_freq_90 = models.BooleanField(default=True)
shuff_freq_180 = models.BooleanField(default=False)
shuff_walk_thru = models.DateTimeField(default=None, null=True, blank=True)
shuff_walk_thru_by = models.SmallIntegerField(models.ForeignKey(Emp,
on_delete=models.CASCADE), default=0)
cust_classification = models.ForeignKey(CustomerClasses,
on_delete=models.CASCADE)
date_updated = models.DateTimeField(auto_now=True, null=True, blank=True)
updated_by = models.SmallIntegerField(default=0)
audit_note = models.TextField(default=None, null=True, blank=True)
audit_exception = models.BooleanField(default=False)
audit_date = models.DateTimeField(auto_now_add=True)
script_exception = models.BooleanField(default=False)
script_exception_date = models.DateTimeField(default=None, null=True,
blank=True)
reports_exception = models.BooleanField(default=False)
reports_exception_date = models.DateTimeField(default=None, null=True,
blank=True)
using_script_credits = models.BooleanField(default=False)
def __str__(self):
return self.company_name
def get_absolute_url(self):
return reverse('cust-detail', args=[self.id])
class CustomerRegions(models.Model):
region = models.CharField(max_length=100)
customer = models.ForeignKey(Customers, on_delete=models.CASCADE)
def __str__(self):
return self.region
FORMS
class CustomerForm(forms.ModelForm):
class Meta:
model = Customers
fields = 'company_name', 'contact1_first_name', \
'contact1_last_name', 'email', 'contact2_first_name', \
'contact2_last_name', 'contact2_email', \
'contact2_phone', 'address1', 'address2', \
'city', 'state', 'zip_code', 'phone', \
'mobile', 'web_address', 'notes', \
'cust_classification', 'logo'
class RegionWCust(forms.ModelForm):
class Meta:
model = CustomerRegions
fields = ('region',)
On Tuesday, June 22, 2021 at 9:47:26 PM UTC-5 [email protected] wrote:
> 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 <(469)%20585-5009>
>> [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/caf5332e-4874-42f2-b5d3-32bab6535af2n%40googlegroups.com.