On Oct 13, 5:33 pm, "Tomasz Nazar" <[EMAIL PROTECTED]> wrote: > Thanks both of you for answers... > > > > On Mon, Oct 13, 2008 at 7:39 PM, Wayne Witzel <[EMAIL PROTECTED]> wrote: > > On Oct 13, 12:14 pm, "Tomasz Nazar" <[EMAIL PROTECTED]> wrote: > >> Hi there! > > >> 1) all model classes are defined in 1 file together with database mapping > > >> That is 2nd most frustrating on my daily work. Even in Pylons tutorial > >> you've advised to mix all the code together in models/__init__.py. > >> Business logic in my small app contains more than 3K of code and is in > >> a single file! > >> I already moved out DB SQLA mappings into separate file, but that's > >> just a tip of the iceberg. > > >> So I ask: why is that? Each model class should be in a separate file > >> (aka Rails, java frameworks, etc) > >> Is reason other than problems with pure Python imports (which don't > >> work well for recursive dependencies)? > >> Why: __init__.py -- there are lot's better names. > >> Also, when one uses IDE and tries to find (by incremental file search) > >> "__init*" there are many of them. Name it domain.py or model.py > >> And finally: any Python ways to split _my_ big file? > > > You can take this as far as you would like. I have my init_model > > method and mappers in model/__init__.py > > My tables and their classes and logic are each in their own file in > > model/tables > > > from project.model.tables import table1 > > > __init__.py is a Python convention and really has nothing to do with > > Pylons. > > Table definitions might be in one place. I don't bother about that. > It's around 50 lines. > What I want is to separate classes definition into separate files / modules. > I always hit the wall with Python saying 'cannot import name ..' -- > cause of recursive dependencies. > And for that I see place of having a doc for that. > > I'm influenced a bit by Java, so I might not fully understand Python modules. > If modules are the only way to separate into files - I'm fine. > I will try again to split with latest Pylons code, maybe I'm having > some stupid bug. But I was trying 2 times and failed. Let's make it 3 > then. >
http://docs.python.org/reference/simple_stmts.html#import Basically, __init__.py turns your directory into a package. Which you can then qualify to get your classes and tables. model __init__.py foo.py class Foo and sa.Table foo_table are both in foo.py __init__.py contains: from model import foo Then you can map them in __init__.py with mapper(foo.Foo, foo.foo_table) > >> 2) SQLAlchemy 2nd level cache > > >> That is most frustrating for me coming from Hibernate, where it's > >> built in. You may point to memcached or whatever, but the truth is it > >> improves performance and coding style hugely! > >> I would love to optimize later and be a bit lazy. > >> Maybe the authors do not have resources -- it's a great soft anyway -- > >> but that should be one of the 1st features on the roadmap. > > > Memcached works great. Why implement an maintain another 2nd level > > caching system when a good one already exists and is very easy to > > plugin to SA? > > > mapper(Foo, foo_table, extension=MemCachedMapper(mc, timeout=35)) > > I don't bother if it's implemented with memcached or any other. I > bother about having it at all. > Don't say to me it's easy to implement. If it's easy then as an author > I'd feel obliged to provide that. Other ORMs in the world have that. > Should I say more.. (?) > I said it was easy to plugin, not implement. > OK. Back to your code? What is this MemCachedMapper.. google 2 hits > only. Is it your own solution, does it work, can you share? > Not my solution, was a solution presented a while back on the SA mailing list. See http://groups.google.com/group/sqlalchemy/msg/5d505529ee157162 I've used it in albeit non-critical, production sites. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to pylons-discuss@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en -~----------~----~----~----~------~----~------~--~---