Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I setup sandman for read-only access? #9

Closed
fccoelho opened this issue Aug 26, 2015 · 2 comments
Closed

How do I setup sandman for read-only access? #9

fccoelho opened this issue Aug 26, 2015 · 2 comments

Comments

@fccoelho
Copy link

Could you post in the readme an example for that? I think this is a very common use case...

@jmcarp jmcarp mentioned this issue Sep 4, 2015
@jmcarp
Copy link

jmcarp commented Sep 4, 2015

I encountered the same issue and wrote up a patch that simplifies the read-only use case by allowing a custom base model. The code is in #13, and it can be used like this:

from sandman2 import model, get_app
from sqlalchemy.ext.automap import automap_base

class Base(model.Model, model.db.Model):
    __abstract__ = True
    __methods__ = {'GET'}
AutomapModel = automap_base(cls=Base)
app = get_app(database_uri, Base=AutomapModel)
app.run()

@jeffknupp
Copy link
Owner

The tests have a simple example of this. From tests/automap_models.py:

from sandman2 import AutomapModel


class User(AutomapModel):

    """A user of the blogging application."""

    __tablename__ = 'user'

    def __unicode__(self):
        return self.name


class Blog(AutomapModel):

    """An online weblog."""

    __tablename__ = 'blog'

    def __unicode__(self):
        return self.name

class Post(AutomapModel):

    """An individual blog post."""

    __tablename__ = 'post'

    def __unicode__(self):
        return self.title

Then simply override the __methods__ property to only support GET:
__methods__ = {'GET'}

Will add to docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants