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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:10:04+00:00 2026-05-24T09:10:04+00:00

I am new to python and I am using django for student database application

  • 0

I am new to python and I am using django for student database application .
Student database application must show id, firstname,lastname,subjectnames,marks.
Single student is having multiple subjects and their marks.
I am getting problem with accessing multiple values that student is having multiple subjects and marks.

models.py

class Person(models.Model):
    firstname=models.CharField(max_length=50)
    lastname=models.CharField(max_length=50)

    def __unicode__(self):
        return (self.firstname,self.lastname)


class Marksheet(models.Model):
    subname=models.CharField(max_length=50)
    marks=models.IntegerField(max_length=10)
    person=models.ForeignKey(Person)

    def __unicode__(self):
        return self.subname

views.py

def add_page(request,page_name): # function for creating  the new records
    p1=None
    p2=None
    if request.method=='POST':
        p1=Person(firstname=request.POST['firstname'],lastname=request.POST['lastname'])
        p1.save()
        p2=Marksheet(subname=request.POST.getlist('subnames'),person=Person(person_id))
        p2.save()
    return render_to_response("add.html",{"page_name":page_name})

creating a records I am using form in html which is shown below….

Templates
add.html

<form method="post" action="/newdcl/{{page_name}}/add/" > {% csrf_token %}
    First name:  <input type="text" name="firstname" /> <br />
    Last name:  <input type="text" name="lastname" /> <br /> 
    Operating System  <input value="os" name="subnames" type="checkbox"><br />
    System Programming <input value="sp" name="subnames" type="checkbox"> <br />
    Maths <input value="maths" name="subnames" type="checkbox"> <br />        
    <input type="submit" value="save" >
</form> 

Can anyone help me in this????

  • 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-24T09:10:04+00:00Added an answer on May 24, 2026 at 9:10 am

    Your problem seems to lie in your how you try to create Marksheet, you can’t assign a list of values to one field like that.
    Using your currently formless, scary, no-validation, setup… you can do something like this-

    p1=Person(firstname=request.POST['firstname'], 
              lastname=request.POST['lastname'])
    p1.save()
    for subname in request.POST.getlist('subnames'):
        new = MarkSheet(subname=subname, person=p1) 
            #no data for marks, must define it to be able to be blank/null
        new.save()
    

    You will need to add blank=True, null=True to you marks field in your models.py if you intend to not have any initial mark.

    Please look at Making Queries and Forms

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

Sidebar

Related Questions

I am new to Python, and I'm working on writing some database code using
New to python and django. Using the forms module and going through the errors
I'm relatively new to Python and am having problems programming with Scapy, the Python
I am extremely new to python, having started to learn it less than a
I'm using Django/Python, but pseudo-code is definitely acceptable here. Working with some models that
Brand new to django. We have a legacy django project using django 0.96x that
I have made an online gallery using Python and Django. I've just started to
Consider a website build using python and django. In many cases it uses 3rd
I'm new to python and django, and when following the Django Book I learned
I a new to django and python. I have however managed to build 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.