Ngalim
did you call generate_mapping before the select?
i've already have the table, it's from mySQL table
Ngalim
should i call generate_mapping?
Ngalim
when i call generate_mapping i've got this error pony.orm.core.ERDiagramError: Cannot define entity 'Employee': database mapping has already been generated
Micaiah
I would handle all of your DB setup in models
Micaiah
http://pastebin.com/T8xE6nxz
Micaiah
Looks like db.bind is getting called *before* Employee is created by the interpreter
Ngalim
hmm .. ok i'll try to fix it
Alexander
Hi Ngalim! db.bind(...) is used to specify database type and parameters of database connection. db.generate_mapping(...) is used to notify Pony: "all necessary entities are defined". At this moment Pony understands which tables should be used to represent specified entities. It is possible to specify create_tables=True option to generate tables, but even if tables are already created, calling generate_mapping is necessary, because this is the moment when Pony creates internal linking between entities and tables. When application is imported, the sequence of operations should be the following: from pony import orm db = Database() class X(db.Entity): ... class Y(db.Entity): ... db.bind(...) db.generate_mapping(...) with db_session: result = select(...) That is, generate_mapping should be called after all entities are defined, but before first select is issued. If you want to put entities in a separate module, I suggest you to define db right in that module, but perform bind and generate_mapping outside of it. This way you separate entity definitions and database configuration options. It may looks something like that: models.py: db = Database() class Person(db.Entity): name = Required(str) controllers.py: from flask import Blueprint from model import db, Person employee_bp = Blueprint(...) main.py: from flask import Flask from controllers import employee_bp from models import db app = Flask(__name__) ... app.register_blueprint(employee_bp) if __name__ == '__main__': db.bind(...) db.generate_mapping() app.run(...)
Ngalim
Hi Ngalim! db.bind(...) is used to specify database type and parameters of database connection. db.generate_mapping(...) is used to notify Pony: "all necessary entities are defined". At this moment Pony understands which tables should be used to represent specified entities. It is possible to specify create_tables=True option to generate tables, but even if tables are already created, calling generate_mapping is necessary, because this is the moment when Pony creates internal linking between entities and tables. When application is imported, the sequence of operations should be the following: from pony import orm db = Database() class X(db.Entity): ... class Y(db.Entity): ... db.bind(...) db.generate_mapping(...) with db_session: result = select(...) That is, generate_mapping should be called after all entities are defined, but before first select is issued. If you want to put entities in a separate module, I suggest you to define db right in that module, but perform bind and generate_mapping outside of it. This way you separate entity definitions and database configuration options. It may looks something like that: models.py: db = Database() class Person(db.Entity): name = Required(str) controllers.py: from flask import Blueprint from model import db, Person employee_bp = Blueprint(...) main.py: from flask import Flask from controllers import employee_bp from models import db app = Flask(__name__) ... app.register_blueprint(employee_bp) if __name__ == '__main__': db.bind(...) db.generate_mapping() app.run(...)
Thank you
Ngalim
i'll fix mine now
Alexey
@luckydonald thank you for reporting bugs and suggesting regarding the editor. We'll fix that. Also, would like to let you know that currently we are working on a new version of the editor. The old version was done using KnockoutJS and it proved to be not very convenient in the long run. The new version is done using React+Redux. Such architecture makes it easier and faster to add new features.
Romet
+1 for react&redux
Святослав
JS 😨
Micaiah
+1 for react&redux
Where is a good place to learn react+redux in a Python context?
Romet
Not sure what you mean by in a Python context but at work we work almost exclusively with a python/django/DRF + react/redux stack
Romet
Don't think there are any guides that talk about specific backends in combination with react/redux that aren't node-based.
Micaiah
Okay thanks!
Micaiah
I'm on code academy and it looks like it is using some node extensions in the background to compile the JSX, what would you use with Django (or in my case Flask) to compile JSX?
Roman
@micaiahparker try https://github.com/facebookincubator/create-react-app
Roman
It's allow you to start working with react without writing tons of configs for webpack/babel/jest etc
Roman
You will run node (webpack) during development and as result you get compiled js file
Micaiah
And then I can link to the compiled JS in a Jinja template for prod?
Roman
Yeah
Micaiah
Sweet! Thanks
Micaiah
Wow, looks like JSX has changed quite a bit since when this code-academy lesson was made.
Artur Rakhmatulin
anyone try to use djony this new version Pony & Django? djony is very old... i think project is dead https://github.com/nnseva/djony
Alexander
I doubt that someone recently used djony, and it may not work with the current version of Pony/Django, but it is possible that the code can be fixed. It may be consiered as a proof of concept that Django/Pony integration is possible
Artur Rakhmatulin
is there any working concept of django and pony now?
Alexander
I think there are no production-ready code at this moment
Alexander
We personally just use Pony+Flask+ReactJS, so integration with Django was not our priority, but later we can add it
Artur Rakhmatulin
I was wrote some logic modules on Python with ponyOrm ) it works and im happy. I will want develop web application with Django like java + spring MVC. And i dont know there any known working methodics what can help me.
Artur Rakhmatulin
ok ) i will read about flask maybe this way better
Roman
Webpack is best solution for now
Artur Rakhmatulin
Wasn't spring the one where you write java code, which gets translated into html/js ?
nowhere ) I dont develop front-end I am just supporting old java project with Java+Spring now. Fron-end was developing with GWT.
Micaiah
Webpack is best solution for now
With webpack is bundle.js path dependent? IE, can I move it to ./static
Roman
@micaiahparker What do you mean? In webpack you can set any (relative or absolute) destination path include './static'
Roman
http://webpack.github.io/docs/configuration.html#output
Lucky
This is about baking a big app.js file right? I was looking into https://github.com/miracle2k/webassets (and flask https://github.com/miracle2k/flask-assets)
Lucky
But I couldn't get around to test it myself
Micaiah
I'm not sure what route webasset wants one to take to actually install javascript libraries..
Lucky
I have a bowser install before that.
Lucky
I guess that would download the files before, I mean I need to get all the python dependencies too, so thats not that problematic to add a extra step there
Romet
@micaiahparker In the company I work at, we publish the project template we use internally for pretty much everything.
Romet
https://github.com/thorgate/django-project-template
Romet
Might be interesting
Mark ☢️
https://github.com/pythonql/pythonql
Mark ☢️
Pony-like thing
Mark ☢️
Alexander
Looks interesting. But this is not a standard Python
stsouko
Hello! Is it possible working with multiple db with cross-links?
stsouko
e.g. user table in db1 and posts in db2?
Alexander
Yes, but you need to process foreign keys manually: class User(db1.Entity): name = Required(str) class Post(db2.Entity): user_id = Required(int) title = Required(str) content = Required(str) ... with db_session: u1 = User.get(name='John') posts = select(p for p in Post if p.user_id == u1.id)
stsouko
ok! Thank you.
stsouko
q2. Can I use Sets bw 2 db?
Alexander
No, but maybe it is not hard to do an equivalent operation without using Sets
stsouko
https://github.com/stsouko/predictor
stsouko
I try to implement project for online predictions of chemical properties and data store
stsouko
this is my db model: https://github.com/stsouko/predictor/blob/master/MWUI/models.py
stsouko
I want to combine 3 db
stsouko
A way for replace set is to implement property with select query?
stsouko
class Users(db_main.Entity): id = PrimaryKey(int, auto=True) active = Required(bool, default=True) email = Required(str, unique=True) password = Required(str) user_role = Required(int) tasks = Set('Tasks') token = Required(str) restore = Optional(str)
Alexander
Why do you want to split data between several databases?
Lucky
Probably because they already are?
stsouko
db_data is db for storing train set data
stsouko
db_pred is users saved predictions.
stsouko
db_main store only articles for web-site
Alexander
What database do you use?
stsouko
postgres
stsouko
data for train can be used separately
Alexander
I think yes, you can define property with select inside to emulate Set across different database. Or just use select directly, like in the example I wrote with users and posts
stsouko
Ok. Thank You! property is more clear.
stsouko
I think
Alexander
If I remember correctly, in PostgreSQL a server is called "database" and a database is called "schema". You can have three different schemata inside the same physial server. In that case, you can use normal Sets between schemata. In order to do this, you need to specify table names manually, as a list or a tuple of two components: schema name and table name. For example: db = Database() # common db object for all schemata class User(db.Entity): _table_ = ['db_main', 'users'] tasks = Set("Task") ... class Task(db.Entity): _table_ = ['db_pred', 'tasks'] user = Required("User") ... By the way, it is better to name entities in a singular form: User instead of Users, etc.
Святослав
Hi. How i can create unique index for column by clause UPPER(column)?
stsouko
In this recipe how to create tables in db? Manually or pony can?