Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8423215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:39:58+00:00 2026-06-10T03:39:58+00:00

I am having the hardest time with my views and formsets saving. I have

  • 0

I am having the hardest time with my views and formsets saving. I have come to realize that views are my weakness in Django. I have been working on this for the past few months and writing and rewriting the code. I know this is the best way to learn. Luckily my team gave me this project to learn from. But I still don’t know where I am going wrong.

If anyone here sees where I am off or pointing me into the right direction, I’d greatly appreciate it. I’m searching for best resources to get stronger in this area.

Here is my Views:

from django.conf import settings
from django.views.generic import View
from django.views.generic import TemplateView
from django.shortcuts import render
from itertools import chain

from .models import *
from .forms import *
from .emailtemplates import OrderFormNotification


class OrderFormProcessor(object):
    def __init__(self, contact=None, contact_form_class=ContactForm,
        letterhead_form_class=LetterHeadFormSet,
        windowenv_form_class=WindowEnvFormSet,
        numbertenenv_form_class=NumberTenEnvFormSet,
        ninebytwelveenv_form_class=NineByTwelveEnvFormSet,
        tenbythirteenenv_form_class=TenByThirteenEnvFormSet,
        businesscard_form_class=BusinessCardFormSet,
        send_notification=False):
    self.contact_form_class = contact_form_class
    self.letterhead_form_class = letterhead_form_class
    self.windowenv_form_class = windowenv_form_class
    self.numbertenenv_form_class = numbertenenv_form_class
    self.ninebytwelveenv_form_class = ninebytwelveenv_form_class
    self.tenbythirteenenv_form_class = tenbythirteenenv_form_class
    self.businesscard_form_class = businesscard_form_class
    self.send_notification = send_notification
    self.contact = contact

def process(self, request, context=None):
    if not context:
        context = {}

    contact = self.contact

    data = request.POST or None

    contact_form = self.contact_form_class(data,
            instance=contact)

    forms = dict(
        contact_form=contact_form,
    )

    formsets = dict(
        letterhead_formset=self.letterhead_form_class(data,                 prefix='letterhead_'),
        windowenv_formset=self.windowenv_form_class(data, prefix='windowenv_'),
        numbertenenv_formset=self.numbertenenv_form_class(data, prefix='numbertenenv_'),
        ninebytwelveenv_formset=self.ninebytwelveenv_form_class(data, prefix='ninebytwelveenv_'),
        tenbythirteenenv_formset=self.tenbythirteenenv_form_class(data, prefix='tenbythirteenenv_'),
        businesscard_formset=self.businesscard_form_class(data, prefix='businesscard_'),
    )

    if request.method == 'POST':
        form_is_valid = all([f.is_valid() for f in forms.values() + \
                formsets.values()])
        if form_is_valid:
            contact = forms['contact_form'].save(commit=False)

            contact.letterhead_form = formsets['letterhead_formset'].save()
            contact.windowenv_form = formsets['windowenv_formset'].save()
            contact.numbertenenv_form = formsets['numbertenenv_formset'].save()
            contact.ninebytwelveenv_form = formsets['ninebytwelveenv_formset'].save()
            contact.tenbythirteenenv_form = formsets['tenbythirteenenv_formset'].save()
            contact.businesscard_form = formsets['businesscard_formset'].save()

            contact.save()

            if self.send_notification:
                email = OrderFormNotification(to=[settings.NO_REPLY_EMAIL_ADDRESS],
                extra_context=data)
                email.send()
        else:
            pass

    all_forms = chain(forms.values(), chain.from_iterable(formsets.values()))
    context = context.copy()
    context.update(forms.items() + formsets.items())
    context.update(
        error_list=list(chain.from_iterable([form.errors.values() for form in all_forms])),
    )

    return (forms, formsets), context


class OrderFormView(View):
    template_name = 'orderform.html'

    def dispatch(self, request, *args, **kwargs):
        processor = OrderFormProcessor(send_notification=True)

        (forms, formsets), context = processor.process(request)
        return render(request, self.template_name, context)


class ThankYou(TemplateView):
    template_name = 'thank-you.html'

Here are my Forms:

from django import forms
from django.forms import ModelForm, extras
from django.forms.models import modelformset_factory
from django.contrib.localflavor import us

from django.forms.widgets import RadioSelect, CheckboxSelectMultiple

from .models import *


class ContactForm(forms.ModelForm):
    address = forms.ChoiceField(required = True, widget=RadioSelect(), choices=ADDRESS_CHOICES,)
    class Meta:
        model = Contact


class LetterHeadForm(forms.ModelForm):
    address = forms.ChoiceField(required = False, widget=RadioSelect(), choices=ADDRESS_CHOICES)
    class Meta:
        model = LetterHead
        widgets = {
            'contact': forms.HiddenInput,
            'quantity': forms.Select(choices=QUANTITY_CHOICES),
        }


class WindowEnvForm(forms.ModelForm):
    address = forms.ChoiceField(required = False, widget=RadioSelect(), choices=ADDRESS_CHOICES)
    class Meta:
        model = WindowEnv
        widgets = {
            'contact': forms.HiddenInput,
            'quantity': forms.Select(choices=QUANTITY_CHOICES),
        }


class NumberTenEnvForm(forms.ModelForm):
    address = forms.ChoiceField(required = False, widget=RadioSelect(), choices=ADDRESS_CHOICES)
    class Meta:
        model = NumberTenEnv
        widgets = {
            'contact': forms.HiddenInput,
            'quantity': forms.Select(choices=QUANTITY_CHOICES),
        }


class NineByTwelveEnvForm(forms.ModelForm):
    address = forms.ChoiceField(required = False, widget=RadioSelect(), choices=ADDRESS_CHOICES)
    class Meta:
        model = NineByTwelveEnv
        widgets = {
            'contact': forms.HiddenInput,
            'quantity': forms.Select(choices=QUANTITY_CHOICES),
        }


class TenByThirteenEnvForm(forms.ModelForm):
    address = forms.ChoiceField(required = False, widget=RadioSelect(), choices=ADDRESS_CHOICES)
    class Meta:
        model = TenByThirteenEnv
        widgets = {
            'contact': forms.HiddenInput,
            'quantity': forms.Select(choices=QUANTITY_CHOICES),
        }


class BusinessCardForm(forms.ModelForm):
    print_choices = forms.ChoiceField(required = True, widget=RadioSelect(), choices=PRINT_CHOICES)
    card_styles = forms.ChoiceField(required = True, widget=RadioSelect(), choices=CARD_CHOICES)
    card_mailing_address = forms.ChoiceField(required = True, widget=RadioSelect(), choices=ADDRESS_CHOICES)
    class Meta:
        model = BusinessCard
        widgets = {
            'contact': forms.HiddenInput,
        }


class RushOrderForm(forms.ModelForm):
    class Meta:
        model = RushOrder
        widgets = {
            'contact': forms.HiddenInput,
            'rush_order': forms.CheckboxInput,
            'in_hand_date': forms.extras.SelectDateWidget
        }


class OrderNoteForm(forms.ModelForm):
    class Meta:
        model = OrderNote
        widgets = {
            'contact': forms.HiddenInput,
            'add_note': forms.CheckboxInput,
            'notes': forms.Textarea
        }


LetterHeadFormSet = modelformset_factory(LetterHead,
    form=LetterHeadForm, extra=2, max_num=2)
WindowEnvFormSet = modelformset_factory(WindowEnv,
    form=WindowEnvForm, extra=2, max_num=2)
NumberTenEnvFormSet = modelformset_factory(NumberTenEnv,
    form=NumberTenEnvForm, extra=2, max_num=2)
NineByTwelveEnvFormSet = modelformset_factory(NineByTwelveEnv,
    form=NineByTwelveEnvForm, extra=2, max_num=2)
TenByThirteenEnvFormSet = modelformset_factory(TenByThirteenEnv,
    form=TenByThirteenEnvForm, extra=2, max_num=2)
BusinessCardFormSet = modelformset_factory(BusinessCard,
    form=BusinessCardForm, extra=2, max_num=2)

Here are the Models:

from django.db import models
from django.forms import ModelForm

from django.utils.translation import ugettext_lazy as _
from django.contrib.localflavor.us.models import PhoneNumberField

PRINT_CHOICES = (
    ('exact reprint', 'Exact Reprint'),
    ('reprint with changes', 'Reprint With Changes'),
    ('new', 'New')
)

QUANTITY_CHOICES = (
    ('1000', '1000'),
    ('2500', '2500'),
    ('5000', '5000')
)

CARD_QUANTITY_CHOICES = (
    ('250', '250'),
    ('500', '500'),
    ('1000', '1000')
)

CARD_CHOICES = (
    ('chef/black', 'Chef/Black'),
    ('executive/red', 'Executive/Red')
)

ADDRESS_CHOICES = (
    ('eisenhower', 'Eisenhower'),
    ('wheeler', 'Wheeler'),
)


class Contact(models.Model):
    first_name = models.CharField(max_length=100, help_text="First Name")
    last_name = models.CharField(max_length=100, help_text="Last Name")
    email_address = models.EmailField(max_length=275)
    address = models.CharField(max_length=10, choices=ADDRESS_CHOICES)

    def __unicode__(self):
        return "%s %s" % (self.first_name, self.last_name)


class BaseStationary(models.Model):
    contact = models.ForeignKey(Contact, related_name='%(class)s_related')
    address = models.CharField(max_length=10, choices=ADDRESS_CHOICES)
    quantity = models.CharField(max_length=4, choices=QUANTITY_CHOICES)

    class Meta:
        abstract = True


class LetterHead(BaseStationary):
    pass


class WindowEnv(BaseStationary):
    pass


class NumberTenEnv(BaseStationary):
    pass


class NineByTwelveEnv(BaseStationary):
    pass


class TenByThirteenEnv(BaseStationary):
    pass


class BusinessCard(models.Model):
    contact = models.ForeignKey(Contact, related_name='businesscards')
    card_first_name = models.CharField(max_length=100)
    card_last_name = models.CharField(max_length=100)
    title = models.CharField(max_length=100)
    print_choices = models.CharField(max_length=19, choices=PRINT_CHOICES)
    card_styles = models.CharField(max_length=12, choices=CARD_CHOICES)
    card_email_address = models.EmailField(max_length=275)
    office_phone_number = PhoneNumberField(_('main office phone number'),
        blank=True, null=True)
    toll_free_number = PhoneNumberField(_('toll free number'),
        blank=True, null=True)
    mobile_number = PhoneNumberField(_('mobile phone number'),
        blank=True, null=True)
    fax_number = PhoneNumberField(_('main office fax'),
        blank=True, null=True)
    card_mailing_address = models.CharField(max_length=10,
        choices=ADDRESS_CHOICES)
    card_quantity = models.CharField(max_length=3,
        choices=CARD_QUANTITY_CHOICES)


class RushOrder(models.Model):
    contact = models.ForeignKey(Contact, related_name='rushorders')
    rush_order = models.BooleanField()
    in_hand_date = models.DateField(blank=True, null=True)


class OrderNote(models.Model):
    contact = models.ForeignKey(Contact, related_name='ordernotes')
    add_note = models.BooleanField()
    notes = models.TextField()

So again what I’m trying to do is get these formsets to save to the database, that way the admin will have the stationary order saved for printing purposes.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T03:40:00+00:00Added an answer on June 10, 2026 at 3:40 am

    Since you’re here to learn, and your code is quite complex (I’d need all the code necessary to reproduce your problem, which includes models), I’m not going to answer with a code fix.

    Instead, you will learn how to use a debugger, which will fix “I still don’t know where I am going wrong”.

    1. Install ipdb, because it’s more convenient than just pdb, pip install ipdb.

    2. Set a breakpoint, in your view, add this line import ipdb; ipdb.set_trace().

    3. Run the code in the devserver, the devserve should pause at the breakpoint, and show the code it’s paused at.

    4. Get to know ipdb, type “h”, it will show a list of command, try to overread the documentation of each command, you can also check this article which includes a video.

    5. Step through your code, by typing “n” in the debugger, the interpreter should move to the next line of code, “d” to step in, “u” to step out, etc … You can execute Python from the prompt at any time.

    You will know what Python is doing exactly, fixing “I still don’t know where I am going wrong”. Also, you’ll become an invincible programmer (or something like that hahaha)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been having the hardest time trying to resolve the weirdest error when
So i have been having the hardest time getting my iphone application approved. And
I am having the hardest time figuring this out, even though it is one
Check this link! I am having the hardest time trying to figure out why
I am having the hardest time trying to figure out this (should be) simple
I'm having the hardest time with this. I don't even understand the error messages
I'm a beginner at Flex, and having the hardest time, working with Effects. Right
I am having the hardest time figuring out something that I think should be
So I'm having the hardest time figuring out what this thing is called, or
I'm having the hardest time getting this to work. I'm trying to copy a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.