How to save all fields in form in single row into the database.

16 views
Skip to first unread message

Salima Begum

unread,
Nov 23, 2020, 7:36:46 AM11/23/20
to django...@googlegroups.com
Hi,

We are trying to save fields in html form into one row into a database.

models.py

class master(models.Model):
    STATUS = (
        ('1', 'Active'),
        ('0', 'InActive'),
    )
    question_code = models.IntegerField()
    question_description = models.CharField(max_length=160)
    category_id = models.IntegerField()
    status = models.CharField(max_length=10, choices=STATUS, default='0')
    question_type = models.CharField(max_length=160)
    added_date = models.DateTimeField()

    def __str__(self):
        return self.questionCode

class Transaction_table(models.Model):
    classifieds_id = models.IntegerField()
    category_id = models.IntegerField()
    question_code = models.IntegerField()
    question_description = models.CharField(max_length=160)
    question_answer = models.CharField(max_length=160)

    def __str__(self):
        return self.classifieds_id

This html form and these are fields these all fields need to save in one row. after submitting the form. Please help me out to achieve this.

<form action="" method="POST">
{% csrf_token %}
  <label for="Sq_Ft">Square ft:</label><br>
  <input type="number" id="Sq_Ft" name="Sq_Ft"><br>
  <label for="Area">Area:</label><br>
  <input type="text" id="Area" name="Area"><br>
  <label for="Landmark">Landmark:</label><br>
  <input type="text" id="Landmark" name="Landmark"><br>
  <label for="Price">Price:</label><br>
  <input type="text" id="Price" name="Price"><br>
  <label for="Make">Make:</label><br>
  <input type="text" id="Make" name="Make"><br>
  <label for="Model">Model:</label><br>
  <input type="text" id="Model" name="Model"><br>
  <label for="Yearofmake">Yearofmake:</label><br>
  <input type="text" id="Yearofmake" name="Yearofmake"><br>
  <label for="Warranty">Warranty:</label><br>
  <input type="text" id="Warranty" name="Warranty"><br>
  <label for="Screensize">Screensize:</label><br>
  <input type="text" id="Screensize" name="Screensize"><br><br>
  <input type="submit" value="Submit">
</form> 

I have a sample data file I am attaching below. In that format I need to save data into the database can anyone please help me out to achieve this.


Thank you
~Salima

Sample.xlsx

Naresh Jonnala

unread,
Nov 23, 2020, 8:12:28 AM11/23/20
to Django users
Reply all
Reply to author
Forward
0 new messages