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 4608744
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:53:19+00:00 2026-05-22T00:53:19+00:00

I have a Django model with a bunch of fields which describe a Work

  • 0

I have a Django model with a bunch of fields which describe a Work Order. I then have a form created with ModelForm, but only using a handful of the model’s field. Here is my form:

class Service_Call_Form(ModelForm):
class Meta:
    model = Work_Order
    fields = ('dateWOCreated', 'dateWORequired', 'problemDescription',
    'resolutionDescription', 'notesToCrew', 'numHours', 'numWorkers')

I have a Create Work Order HTML template that shows all fields, but NOT “resolutionDescription”. In contrast, there is a Work Order Completed HTML template that shows only the “resolutionDescription” field (since, all the user needs to do is explain how the problem was resolved, and not edit what the original problem was).

Now, what I don’t understand is that when I click the “Save” button in my template form to complete the work order, all the fields that are shown for the Create Work Order template are cleared out to blank, and the problem resolution field remains. Also, all model fields which I set within the view (and, thus, are not editable by the user) remain in tack.

Why would this be happening?

My Views:

def create_service_call(request):
if request.method == 'POST':
    form = Service_Call_Form(request.POST)
    if form.is_valid():
        wo = form.save(commit=False)
        if wo.woID == None:
            wo.woID = new_wo_id()
        wo.dateWOCreated = datetime.date.today()
        wo.systemID = System.objects.get(systemID='2')
        wo.woType = 'R'
        wo.isComplete = 'N'
        wo.save()
        return HttpResponseRedirect('/work-orders/')
else:
        form = Service_Call_Form()
return render_to_response("pages/work_orders/create_service_call.html", {'form': form}, context_instance=RequestContext(request))


def complete_service_call(request, scwoID):
if request.method == 'POST':
    woEdit = Work_Order.objects.get(pk=scwoID)
    form = Service_Call_Form(request.POST, instance = woEdit)
    if form.is_valid():
        form.save()
        return HttpResponseRedirect('/work-orders/')
else:
    if scwoID == None:
        #Really, this should never happen (not have a woID in the url)
        return HttpResponseRedirect('/work-orders/', context_instance=RequestContext(request))
    else:
        wo = Work_Order.objects.get(pk=scwoID)
        form = Service_Call_Form(instance=wo)
return render_to_response("pages/work_orders/complete_service_call.html", {'form': form}, context_instance=RequestContext(request))

The Model:

class Work_Order(models.Model):
IS_COMPLETE_CHOICES = (
    ('Y', 'Yes'),
    ('N', 'No'),
)

WO_TYPE_CHOICES = (
    ('P', 'Plumb'),
    ('I', 'Install'),
    ('S', 'Show'),
    ('R', 'Service'),
    ('B', 'Blow down'),
    ('U', 'Start up'),
)

woID = models.CharField(max_length = 10, primary_key = True, default = new_wo_id(), verbose_name = 'Work Order ID')
woType = models.CharField(max_length = 2, verbose_name = 'WO Type', default='R', choices = WO_TYPE_CHOICES)
systemID = models.ForeignKey(System, verbose_name = 'System ID')
notesToCrew = models.TextField(blank = True, null = True, verbose_name = 'Notes to Crew')
dateWOCreated = models.DateField(blank = True, null = True, default=datetime.date.today(), verbose_name = 'Date Created')
dateWORequired = models.DateField(blank = True, null = True, verbose_name = 'Date Required')
numDays = models.DecimalField(max_digits = 3, decimal_places = 0, verbose_name = 'Number of Days to Complete', blank = True, null = True)
numHours = models.DecimalField(max_digits = 3, decimal_places = 2, verbose_name = 'Number of Hours to Complete', blank = True, null = True)
isComplete = models.CharField (max_length = 3, default = 'N', verbose_name = 'Is WO Complete?', choices = IS_COMPLETE_CHOICES)
problemDescription = models.TextField(verbose_name = 'Problem Description', blank = True, null = True)
resolutionDescription = models.TextField(verbose_name = 'Resolution Description', blank = True, null = True)
numWorkers = models.DecimalField(max_digits = 3, decimal_places = 0, verbose_name = 'Number of Workers Required', blank = True, null = True)

def __unicode__(self):
    return u'%s - %s' % (self.woID, self.systemID.systemAddress)

class Meta:
    ordering = ['woID']
  • 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-05-22T00:53:20+00:00Added an answer on May 22, 2026 at 12:53 am

    You should have two forms, as you have two completely different types of data being inputed. The first can be a ModelForm (as it saves a bunch of fields to a Model):

    class Service_Call_Form(ModelForm):
        class Meta:
            model = Work_Order
            fields = ('dateWOCreated', 'dateWORequired', 'problemDescription',
                      'notesToCrew', 'numHours', 'numWorkers')
    

    and one just containing ResolutionDescription which I’d just leave as a regular form (as it only updates one field in a model). You may also want model id to be a hidden field, if its not present in the URL or makes it to the request.POST otherwise.

    class Resolution_Description_Form(forms.Form):
         resolution_description = forms.TextField(max_length=100)
    

    If the the template was from Service_Call_Form your view saved correctly; if you have something with resolution_description, you should just update that field in a function like:

    def complete_work_order(request, scwoID):
        if request.method == 'POST':
            woEdit = Work_Order.objects.get(pk=scwoID)
            form = Resolution_Description_Form(request.POST)
            if form.is_valid():
                woEdit.resolution_description = form.cleaned_data.get('resolution_description')
                woEdit.save()
                return HttpResponseRedirect('/work-orders/')
         ...
    

    EDIT:you could also just have just two ModelForm if you wanted. E.g.,

    class Resolution_Description_Form(ModelForm):
        class Meta:
            model = Work_Order
            fields = ('resolutionDescription', )
    

    and just use the appropriate ModelForm in the appropriate template and save as you were saving before.

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

Sidebar

Related Questions

I have Django Model with many fields which user must fill. If I'll create
I have a django model that I'm displaying as a form using a ModelForm.
I have a django model which has a load of relatively small fields and
I have a Django model with a large number of fields and 20000+ table
I have a Django form that uses an integer field to lookup a model
I have a model with a bunch of fields. Two of the fields have
I have a django model which i would call as base model. I have
I have a Django model with some fields that have default values specified. I
I have a Django model for Cat which has a foreign key Dog .
I have a Django model which I need to hold a callable (in this

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.