python

Anonymous
plain_text
01/02/2023 5:31 PM
584 B
15
Indexable
import conn
from conn import Animals, session

class Animal:

    def __init__(self, name, age):

        self.name = name
        self.age = age

    def add_to_database(self, animal):

        animal = [vars(animal)]
        session.add_all(Animals(**animal) for animal in animal)
        return session.commit()



# bunny = Animal('Ruda', 5)
#
# bunny.add_to_database(bunny)

horsey = Animal('Siwy', 10)
horsey.add_to_database(horsey)
Editor is loading...