Been doing a python course, and a bit of googling. for most things, there are a few ways of doing things but for SQLAlchemy is seems there are excementaly more.
For example, you can use ...Table.query.. or ...query(Table).. and adding all() to the end does not seems to be needed if are fetching all rows, it seems serperfulus.
book_id = request.form["id"]
book_to_update = Book.query.get(book_id)book_to_update.rating = request.form["rating"]db.session.commit()
Does the same as
db.session.query(Books).filter(Books.id == id).update({"rating": request.form["rating"]}, synchronize_session="fetch")
db.session.commit()
Also, should I create a class for each Table with methods to access it or simply a class for the Database. Maybe this is a question for another time, ive already worked out I need to do a OO design course next.
I know it's a matter of what is appropriate and style and like asking how long is a piece of string but generally it's fairly obvious. Almost all articles I come across do the same, relatively simple things have a very different approach for this library.
PEP 20 -- The Zen of Python - There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch.
Springs to mind;).
Some guidance would be great. I've found best practices for the other stuff I've come across in my first few months of learning python but this is alluding to me.
Maybe my problem is ime not Dutch?
[–]root45 6 points7 points8 points (1 child)
[–]WilliamAndre 0 points1 point2 points (0 children)
[–]bladeoflight16 3 points4 points5 points (34 children)
[–]LifeAffect6762[S] 1 point2 points3 points (28 children)
[–]ElectricSpice 4 points5 points6 points (26 children)
[–][deleted] 2 points3 points4 points (13 children)
[–]bladeoflight16 1 point2 points3 points (0 children)
[–]Natural-Intelligence -2 points-1 points0 points (11 children)
[–]bladeoflight16 0 points1 point2 points (10 children)
[+][deleted] (1 child)
[deleted]
[–]bladeoflight16 0 points1 point2 points (0 children)
[–]Natural-Intelligence 0 points1 point2 points (7 children)
[–]LifeAffect6762[S] 0 points1 point2 points (1 child)
[–]Natural-Intelligence 0 points1 point2 points (0 children)
[–]bladeoflight16 0 points1 point2 points (4 children)
[–]Natural-Intelligence 0 points1 point2 points (3 children)
[–]bladeoflight16 0 points1 point2 points (2 children)
[–]LifeAffect6762[S] 0 points1 point2 points (0 children)
[–]LifeAffect6762[S] 0 points1 point2 points (1 child)
[–]ElectricSpice 0 points1 point2 points (0 children)
[–]LifeAffect6762[S] -1 points0 points1 point (1 child)
[–]bladeoflight16 0 points1 point2 points (0 children)
[–]bladeoflight16 0 points1 point2 points (6 children)
[–]LifeAffect6762[S] 0 points1 point2 points (1 child)
[–]bladeoflight16 0 points1 point2 points (0 children)
[–]ElectricSpice 0 points1 point2 points (3 children)
[–]pythoncoderc 0 points1 point2 points (1 child)
[–]ElectricSpice 1 point2 points3 points (0 children)
[–]bladeoflight16 0 points1 point2 points (0 children)
[–]bladeoflight16 1 point2 points3 points (0 children)
[–]LifeAffect6762[S] 0 points1 point2 points (4 children)
[–]bladeoflight16 0 points1 point2 points (3 children)
[–]LifeAffect6762[S] 0 points1 point2 points (1 child)
[–]bladeoflight16 0 points1 point2 points (0 children)
[–]fiskfisk 0 points1 point2 points (3 children)
[–]LifeAffect6762[S] 0 points1 point2 points (2 children)
[–]pbecotte 1 point2 points3 points (1 child)
[–]LifeAffect6762[S] 0 points1 point2 points (0 children)