Re: [sqlalchemy] Re: Organizing a project

2019-03-04 Thread Rich Shepard

On Mon, 4 Mar 2019, Jonathan Vanasco wrote:


We "define" the model in a separate package - all the classes and
relationships are in there. There are database support items as well, and
some of the advanced/business logic that manipulate the ORM objects. By
advanced-database-specific logic, an example might be: resetting a
password is a function that checks the existing password against current &
past ones, updates the current credentials table, and migrates a consumed
credential into a table of invalid previously used options - it's a
multi-step database update.


Jonathan,

Thanks for clarifying.

For this and the next application I need to build the model (in model.py) is
the SQLAlchemy translation of the postgres tables; with this application
there are 9 tables/classes. No other application will use these.


The webapps typically have a "model" namespace, but that just invokes the
'shared' model package and contains any application/implementation
specific model logic. Everything is written so it can be easily migrated
into the shared model package so all of the coordinated apps/utilities can
leverage it.


I have a module called commonDlgs.py which contains re-useable classes, such
as password login, quitter (asks 'Are you sure?'), and generic message box.


This is just a personal preference my I have gravitated towards with my
team over the past few years.


You're really helped me resolve my questions. Now I know that I can put
classes in whatever modules and subdirectories I want as long as import them
where they are used, and it really doesn't matter what the structure is so
long as it is easy for others to follow. The current application is for my
business needs; the next one will be given away and hosted on github.

Regards,

Rich

--
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper


http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.

To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] Re: Organizing a project

2019-03-04 Thread Jonathan Vanasco
We "define" the model in a separate package - all the classes and 
relationships are in there. There are database support items as well, and 
some of the advanced/business logic that manipulate the ORM objects.  By 
advanced-database-specific logic, an example might be: resetting a password 
is a function that checks the existing password against current & past 
ones, updates the current credentials table, and migrates a consumed 
credential into a table of invalid previously used options - it's a 
multi-step database update.   

The webapps typically have a "model" namespace, but that just invokes the 
'shared' model package and contains any application/implementation specific 
model logic.  Everything is written so it can be easily migrated into the 
shared model package so all of the coordinated apps/utilities can leverage 
it.

This is just a personal preference my I have gravitated towards with my 
team over the past few years.  We've just never built a MVC app where the 
model only serves a single app after a few months.  There are always new 
tools/services/etc needed and this approach keeps everything centralized... 
especially many of the test suites.  One "project" was originally a Pyramid 
app that has grown to also be a Celery Utility, Twisted Daemon with 9 
services, and about 50 python tools. They all use a central SqlAlchemy 
model.

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] Re: Organizing a project

2019-03-04 Thread Rich Shepard

On Sun, 3 Mar 2019, Jonathan Vanasco wrote:


I generally write the SqlAlchemy models as a separate package, then import
that into my MVC/etc patterned app.



In terms of the SqlAlchemy logic, some of that I keep in the models
package, others are in the core app.

...

So my general advice is to approach things with two packages, one for [M]
and the other for [VC]


Jonathan,

I see three different approaches in the above: 1) a separate SA package; 2)
some SA in the model, some in the application class; and 3) a model module
and a combined view/controller module. Please help me distinguish among
them.

Regards,

Rich

--
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper


http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.

To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] Re: Organizing a project

2019-03-03 Thread Jonathan Vanasco
I generally write the SqlAlchemy models as a separate package, then import 
that into my MVC/etc patterned app.

In terms of the SqlAlchemy logic, some of that I keep in the models 
package, others are in the core app.

This allows other apps and utilities to be built off the SqlAlchemy models 
and be imported cleanly.  This way cron jobs, migrations, admin tools, etc 
etc can just leverage a shared central model, which is fairly lean.  So my 
general advice is to approach things with two packages, one for [M] and the 
other for [VC]



On Sunday, March 3, 2019 at 6:19:29 PM UTC-5, Rich wrote:
>
> Starting my first SA project (have one more planned after this one's 
> working) and appreciate advice on organizing project files. I understand 
> the 
> MVC pattern and am trying to apply it with subdirectories of model/, 
> view/, 
> and controller/ yet I'm unsure where to place SQLAlchemy. 
>
> This is the overall structure: the backend is a postgresql database, SA 
> will 
> access it via psycopg2 (the engine should be properly configured for 
> this), 
> and the GUI is being written using tkinter. 
>
> Now, ../model/model.py has the classes that represent the postgres table; 
> ../views/ contains four files: data_entry_dialogs.py, ttkcalendar.py, 
> commonDlgs.py, and data_entry_validators.py; and ../controller/ is empty. 
>
> One of the classes in data_entry_dialogs.py has two ttk.Combobox widgets 
> whose values are in two classes in models.py. I assume that a properly 
> structured SA statement (not yet written or tested) can select the rows 
> from 
> the two tables, store them in a list, and that list passed to the 
> ttk.Comboboxes for their input_arg values. I'll work on an appropriate 
> statement RSN, but now want to learn whether to put all SA code in 
> models.py, in the model/ directory, or the controller/ directory. 
>
> If this is in the ORM tutorial I've missed seeing it so pointers to docs 
> that address these two issues are very welcome. 
>
> TIA, 
>
> Rich 
>
>

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.