python

mail@pastecode.io avatar
unknown
plain_text
2 years ago
438 B
1
Indexable
Never
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)