Python Forum
Inserting multiple rows in a single request.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Inserting multiple rows in a single request.
#1
How to insert multiple rows in a single request using flask-sqlalchemy.
class relatives(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    main_id = db.Column(db.Integer, db.ForeignKey('maindevotee.id'), nullable=False)
    name = db.Column(db.String(225))
    star = db.Column(db.String(225))
    gender = db.Column(db.String(45))
    relation = db.Column(db.String(45))

    def json(self):
        return {'main_id': self.main_id, 'name': self.name, 'star':self.star,
                'gender': self.gender, 'relation': self.relation}
    def add_relatives(_main_id, _name, _star, _gender, _relation):
        new_relative = relatives(main_id=_main_id, name=_name, star=_star, gender=_gender,
                                 relation=_relation)
        db.session.add(new_relative)
        db.session.commit()
I am unable to insert multiple rows(multiple objects) in a table.How it is possible. I mean i want to add more than one row in a single request.

@app.route('/relatives',methods=['GET','POST'])
def relative():
    request_data = request.get_json()
    relatives.add_relatives(request_data['main_id'], request_data['name'], request_data['star'],
                            request_data['gender'], request_data['relation'])
    response = Response('Relative added', 201, mimetype='application/json')
    return response
Reply


Messages In This Thread
Inserting multiple rows in a single request. - by swaroop - Jan-09-2021, 10:36 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How would I alter this to a single api request? SuchUmami 1 717 Jun-24-2023, 08:30 AM
Last Post: ferdnyc
  python script for inserting rows into hbase table lravikumarvsp 7 7,013 Mar-24-2023, 04:44 AM
Last Post: parth_botadara
  Create multiple/single csv file for each sql records mg24 6 1,325 Sep-29-2022, 08:06 AM
Last Post: buran
  Reshaping a single column in to multiple column using Python sahar 7 1,970 Jun-20-2022, 12:35 PM
Last Post: deanhystad
  Split single column to multiple columns SriRajesh 1 1,290 Jan-07-2022, 06:43 PM
Last Post: jefsummers
  The code I have written removes the desired number of rows, but wrong rows Jdesi1983 0 1,603 Dec-08-2021, 04:42 AM
Last Post: Jdesi1983
  Delete multiple comments with a single API call (facebook) Ascalon 0 2,269 Dec-04-2021, 08:33 PM
Last Post: Ascalon
  Slittping table into Multiple tables by rows drunkenneo 1 2,005 Oct-06-2021, 03:17 PM
Last Post: snippsat
  How can I assign "multiple variables" to a single "value"? Psycpus 2 1,810 Oct-04-2021, 03:29 AM
Last Post: deanhystad
  how can I correct the Bad Request error on my curl request tomtom 8 4,969 Oct-03-2021, 06:32 AM
Last Post: tomtom

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020