Skip to content

Instantly share code, notes, and snippets.

@jlafon
Created May 21, 2014 14:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jlafon/2f9884a4aabc9483ba52 to your computer and use it in GitHub Desktop.
Save jlafon/2f9884a4aabc9483ba52 to your computer and use it in GitHub Desktop.
Default attribute values
from pynamodb.models import Model
from pynamodb.attributes import UnicodeAttribute
def make_id():
return somerandomid
class Thread(Model):
table_name = 'Thread'
forum_name = UnicodeAttribute(hash_key=True)
another_field = UnicodeAttribute(hash_key=True)
def __init__(self, *args, **kwargs):
custom_id = make_id()
kwargs.setdefault("forum_name", custom_id)
kwargs.setdefault("another_field", custom_id)
super(Thread, self).__init__(*args, **kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment