-
Notifications
You must be signed in to change notification settings - Fork 427
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
Regions as attributes #9
Comments
Hi John, I agree that something should be done to avoid attribute name collisions, and I will leave this issue open for a while to let people comment on it before deciding how to fix it. My goal is to keep the Model API simple and Pythonic. With that in mind, here are two possible solutions.
from pynamodb.models import Model
from pynamodb.attributes import UnicodeAttribute
class UserModel(Model):
"""A user model class"""
class Meta:
"""A class for settings"""
table_name = "users"
region = "us-east-1"
user_name = UnicodeAttribute(hash_key=True)
from pynamodb.models import Model
from pynamodb.attributes import UnicodeAttribute
class UserModel(Model):
"""A user model class"""
table_name = "users"
user_name = UnicodeAttribute(hash_key=True)
# This would have to be done before using UserModel
UserModel.set_region('us-east-1') |
Hi, I'm in favour of the On this note, how is one supposed to use a PynamoDB Model with DynamoDBLocal? There's nowhere to set the endpoint url, which would be another |
@adamchainz , using There are two ways to set the endpoint URL for now: from pynamodb.models import Model
from pynamodb.connection import TableConnection
class TestModel(Model):
connection = TableConnection('table-name', host='http://localhost') or from pynamodb.models import Model
from pynamodb.connection import TableConnection
class TestModel(Model):
# normal attributes here
TestModel.connection = TableConnection(TestModel.table_name, host='http://localhost') If we change the API to include a from pynamodb.models import Model
from pynamodb.attributes import UnicodeAttribute
class UserModel(Model):
"""A user model class"""
class Meta:
"""A class for settings"""
table_name = "users"
region = "us-east-1"
host = 'http://localhost'
user_name = UnicodeAttribute(hash_key=True) |
👍 for |
I implemented the |
I like the idea of adding the region to the Model, but if you are already using region as an attribute (say because you use the table to track aws resources), you get an error (dynamodb not available in this region).
Not sure if this is solvable other than by A. 'region' is not an allowed attribute name or B. change the way the table regions are set/stored. In any case, this is an issue I figured you should be aware of.
Thanks for all your hard work.
The text was updated successfully, but these errors were encountered: