[GH-ISSUE #9] How do I setup sandman for read-only access? #3

Closed
opened 2026-02-26 01:32:51 +03:00 by kerem · 2 comments
Owner

Originally created by @fccoelho on GitHub (Aug 26, 2015).
Original GitHub issue: https://github.com/jeffknupp/sandman2/issues/9

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

Originally created by @fccoelho on GitHub (Aug 26, 2015). Original GitHub issue: https://github.com/jeffknupp/sandman2/issues/9 Could you post in the readme an example for that? I think this is a very common use case...
kerem closed this issue 2026-02-26 01:32:51 +03:00
Author
Owner

@jmcarp commented on GitHub (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()
<!-- gh-comment-id:137621223 --> @jmcarp commented on GitHub (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: ``` python 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() ```
Author
Owner

@jeffknupp commented on GitHub (Sep 16, 2015):

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.

<!-- gh-comment-id:140911473 --> @jeffknupp commented on GitHub (Sep 16, 2015): 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 in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/sandman2-jeffknupp#3
No description provided.