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.
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(''), 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':, '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,
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.

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
I am thinking you need to pass a list then iterate over the list.
(Jan-09-2021, 09:06 PM)robsuttonjr Wrote: I am thinking you need to pass a list then iterate over the list.

Can you please send me the correct code.

Possibly Related Threads…
Thread Author Replies Views Last Post
  Ploting single column with multiple category drunkenneo 1 328 May-26-2021, 04:51 PM
Last Post: jefsummers
  Pandas DataFrame combine rows by column value, where Date Rows are NULL rhat398 0 215 May-04-2021, 10:51 PM
Last Post: rhat398
  Indexing [::-1] to Reverse ALL 2D Array Rows, ALL 3D, 4D Array Columns & Rows Python Jeremy7 8 1,100 Mar-02-2021, 01:54 AM
Last Post: Jeremy7
  Pandas: how to split one row of data to multiple rows and columns in Python GerardMoussendo 4 844 Feb-22-2021, 06:51 PM
Last Post: eddywinch82
  How to filter out Column data From Multiple rows data? firaki12345 10 906 Feb-06-2021, 04:54 AM
Last Post: buran
  Fetching data from multiple tables in a single request. swaroop 0 301 Jan-09-2021, 04:23 PM
Last Post: swaroop
  How to append multiple <class 'str'> into a single List ahmedwaqas92 2 469 Jan-07-2021, 08:17 AM
Last Post: ahmedwaqas92
  Scripting: Multiple Votes With a Single Click or Button Ovidiu 0 441 Jul-07-2020, 10:51 AM
Last Post: Ovidiu
  ImportError: cannot import name 'Request' from 'request' abhishek81py 1 1,337 Jun-18-2020, 08:07 AM
Last Post: buran
  Inserting values from multiple lists sqlite azulu 1 708 May-24-2020, 08:40 AM
Last Post: ibreeden

Forum Jump:

User Panel Messages

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