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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:07:16+00:00 2026-05-21T14:07:16+00:00

I am building a webapp which will be used by a company to carry

  • 0

I am building a webapp which will be used by a company to carry out their daily operations. Things like sending invoices, tracking accounts receivable, tracking inventory (and therefore products). I have several models set up in my various apps to handle the different parts of the web-app. I will also be setting up permissions so that managers can edit more fields than, say, an office assistant.

This brings me to my question. How can I show all fields of a model and have some that can be edited and some that cannot be edited, and still save the model instance?

For example, I have a systems model for tracking systems (we install irrigation systems). The system ID is the primary key, and it is important for the user to see. However, they cannot change that ID since it would mess things up. Now, I have a view for displaying my models via a form using the “form.as_table”. This is efficient, but merely spits out all the model fields with input fields filling in the values stored for that model instance. This includes the systemID field which should not be editable.

Because I don’t want the user to edit the systemID field, I tried making it just a label within the html form, but django complains. Here’s some code:

my model (not all of it, but some of it):

class System(models.Model):

systemID = models.CharField(max_length=10, primary_key=True, verbose_name = 'System ID')
systemOwner = models.ForeignKey (System_Owner)
installDate = models.DateField()
projectManager = models.ForeignKey(Employee, blank=True, null=True)

#more fields....

Then, my view for a specific model instance:

def system_details(request, systemID):
if request.method == 'POST':
    sysEdit = System.objects.get(pk=systemID)
    form = System_Form(request.POST, instance=sysEdit)
    if form.is_valid():
        form.save()
        return HttpResponseRedirect('/systems/')
else:
    sysView = System.objects.get(pk=systemID)
    form = System_Form(instance=sysView)

return render_to_response('pages/systems/system_details.html', {'form': form}, context_instance=RequestContext(request))

Now the html page which displays the form:

<form action="" method="POST">
{% csrf_token %}
<table>
  {{ form.as_table }}
</table>
<input type="submit" value="Save Changes">
<input type="button" value="Cancel Changes" onclick="window.location.href='/systems/'">
</form>

So, what I am thinking of doing is having two functions for the html. One is a form for displaying only those fields the user can edit, and the other is for just displaying the content of the field (the systemID). Then, in the view, when I want to save the changes the user made, I would do:

sysValues = System.objects.get(pk=SystemID)
form.save(commit = false)
form.pk = sysValues.sysValues.pk (or whatever the code is to assign the sysValues.pk to form.pk)

Is there an easier way to do this or would this be the best?

Thanks

  • 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-21T14:07:17+00:00Added an answer on May 21, 2026 at 2:07 pm

    One thing you can do is exclude the field you don’t need in your form:

    class System_Form(forms.ModelForm):
        class Meta:
            exclude = ('systemID',)
    

    The other is to use read-only fields: http://docs.djangoproject.com/en/1.3/ref/contrib/admin/#django.contrib.admin.ModelAdmin.readonly_fields as @DTing suggessted

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

Sidebar

Related Questions

I am building a simple C# web app which will act like an online
I am building a demo dataset for my webapp. I would like thousands of
I'm writing a web app which is used a SaS. Each customer has their
We're going to be building some J2ME apps and Java/Rails webapps which will have
I am building an application for a friend's event company. The software will only
I am building a custom component for my webapp that will benchmark each service,
We are building a web app which will have a lot of images being
I'm building a webapp for a department on a large college campus that will
I'm currently building a web app (atop Ruby on Rails), which will let users
I'm working on a large webapp, which (among other things) has a table which

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.