using flask-sqlalchemy without the subclassed declarative base
Question: I am using Flask for my python wsgi server, and sqlalchemy for all my database
access.

I _think_ I would like to use the Flask-Sqlalchemy extension in my
application, but I do not want to use the declarative base class (db.Model),
instead, I want to use the base from sqlalchemy.ext.declarative.

Does this defeat the entire purpose of using the extension?

* * *

My use case:

I would like the extension to help me manage sessions/engines a little better,
but I would like to handle all models separately.

I actually wouldn't mind using the extension, but I want to write _strict_
models. I am porting code from a non-flask application, and I will be pushing
changes back to that project as I go. If flask-sqlalchemy allows me to cheat
on Table **metadata** for instance, that is going to cause problems when the
code is pushed back out. There are also portions of my code that do lots of
type checking (polymorphic identities), and I also remember reading that type
checking on Table is not recommended when using the extension.


Answer: You can have Flask-SQLAlchemy expose your own base Model instead of it's
built-in one. Just subclass `SQLAlchemy` and override `make_declarative_base`.

    
    
    from flask.ext.sqlalchemy import SQLAlchemy
    
    
    class CustomAlchemy(SQLAlchemy):
        def make_declarative_base(self):
            base = declarative_base(...)
            ...
            return base
    
    db = CustomAlchemy()
    

