I am trying to build a User model for python. I have to insert values into a a database using SQL_Alchemy ORM. For this I have defined a class User
which has attributes id,first_name,second_name,last_name,email etc
. The class inherits the db.Model and the attirbutes and coloumns are mapped accordingly. The implementation of the class is given below:
class Users(db.Model):
__tablename__ = 'users'
id = db.Coloumn('id',db.Integer,primary_key=True)
first_name = db.Coloumn('first_name',db.String)
second_name = db.Coloumn('second_name',db.String)
last_name = db.Coloumn('last_name',db.String)
email = db.Coloumn('email',db.String)
password = db.Coloumn('password',db.String)
I want to implement a method name insert() which takes value as an argument and maps it to the class attributes dynamically.
For now I have implemented it the following way:
def insert(self,first_name,second_name,last_name,email,password):
self.first_name = first_name
self.second_name = second_name
self.last_name = last_name
self.email = email
self.password = password
I want to implement the method in such a way that dictionary values as an kwargument and maps it to the the class attributes accordingly.
For example the method should be declared as
insert(self,**kwargs):