Monday, November 23, 2020

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


For your reference:

https://docs.djangoproject.com/en/3.1/ref/forms/api/#django.forms.Form.prefix



On Monday, November 23, 2020 at 6:06:46 PM UTC+5:30 sali...@rohteksolutions.com wrote:
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

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/aa95ba98-ccf5-47b8-b314-bce7406f4421n%40googlegroups.com.

No comments:

Post a Comment