Python google.appengine.ext.db.ReferenceProperty() Examples

The following are 7 code examples of google.appengine.ext.db.ReferenceProperty(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module google.appengine.ext.db , or try the search function .
Example #1
Source File: pager.py    From browserscope with Apache License 2.0 5 votes vote down vote up
def _decode_bookmark(self, bookmark):
        """Decodes a bookmark and prepares the values to be used on queries.
        Currently supported properties are DateTimeProperty, FloatProperty,
        IntegerProperty, StringProperty and ReferenceProperty.

        Returns:
          A dictionary of property names/values to be used in queries.
        """
        required = list(self._bookmark_properties)
        required.append('_')
        try:
            bookmark = decode_bookmark(bookmark)
            # Ensure that all required values are available.
            for key in required:
                if key not in bookmark:
                    return None
        except:
            return None

        for key in required:
            value = bookmark[key]
            if key == '_':
                self._first_result = bookmark[key]
            elif key == '__key__':
                bookmark[key] = db.Key(value)
            else:
                prop = getattr(self._model_class, key)
                if isinstance(prop, db.ReferenceProperty):
                    bookmark[key] = db.Key(value)
                elif isinstance(prop, db.DateTimeProperty):
                    bookmark[key] = parseDateTime(value)
                else:
                    bookmark[key] = prop.data_type(value)

        return bookmark

# from http://kbyanc.blogspot.com/2007/09/python-reconstructing-datetimes-from.html 
Example #2
Source File: db.py    From jbox with MIT License 5 votes vote down vote up
def convert_ReferenceProperty(model, prop, kwargs):
    """Returns a form field for a ``db.ReferenceProperty``."""
    kwargs['reference_class'] = prop.reference_class
    kwargs.setdefault('allow_blank', not prop.required)
    return ReferencePropertyField(**kwargs) 
Example #3
Source File: db.py    From RSSNewsGAE with Apache License 2.0 5 votes vote down vote up
def convert_ReferenceProperty(model, prop, kwargs):
    """Returns a form field for a ``db.ReferenceProperty``."""
    kwargs['reference_class'] = prop.reference_class
    kwargs.setdefault('allow_blank', not prop.required)
    return ReferencePropertyField(**kwargs) 
Example #4
Source File: db.py    From googleapps-message-recall with Apache License 2.0 5 votes vote down vote up
def convert_ReferenceProperty(model, prop, kwargs):
    """Returns a form field for a ``db.ReferenceProperty``."""
    kwargs['reference_class'] = prop.reference_class
    kwargs.setdefault('allow_blank', not prop.required)
    return ReferencePropertyField(**kwargs) 
Example #5
Source File: recipe-578229.py    From code with MIT License 5 votes vote down vote up
def __new__(cls, name, bases, dct):
        myname = name.replace('ConnectionModel','').lower()
        if myname:
            #this is not the baseclass
            to_collection_name = 'myto_%s_connections' % myname #or any other naming scheme you like
            from_collection_name = 'myfrom_%s_connections' % myname #or any other naming scheme you like
            myto = 'myto_%s'%myname
            myfrom = 'myfrom_%s'%myname
            dct[myto] = db.ReferenceProperty(collection_name = to_collection_name)
            dct[myfrom] = db.ReferenceProperty(collection_name = from_collection_name)
            if 'put' in dct:
                myput = dct['put']
            else:
                myput = None

            def put(self):
                setattr(self, myto, self.myto)
                setattr(self, myfrom, self.myfrom)
                self._validate_connected_types()
                if myput is not None:
                    myput(self)
                else:
                    MyClass = eval(name)
                    super(MyClass, self).put()
            dct['put'] = put
                
        return super(ConnectionModelMetaclass, cls).__new__(cls, name, bases, dct) 
Example #6
Source File: djangoforms.py    From python-compat-runtime with Apache License 2.0 5 votes vote down vote up
def get_form_field(self, **kwargs):
    """Return a Django form field appropriate for a reference property.

    This defaults to a ModelChoiceField instance.
    """
    defaults = {'form_class': ModelChoiceField,
                'reference_class': self.reference_class}
    defaults.update(kwargs)
    return super(ReferenceProperty, self).get_form_field(**defaults) 
Example #7
Source File: djangoforms.py    From python-compat-runtime with Apache License 2.0 5 votes vote down vote up
def get_value_for_form(self, instance):
    """Extract the property value from the instance for use in a form.

    This return the key object for the referenced object, or None.
    """
    value = super(ReferenceProperty, self).get_value_for_form(instance)
    if value is not None:
      value = value.key()
    return value