[google-appengine] Reference properties and ordering results

2010-02-24 Thread Alex
Hi,
Is it possible to do anything with a reference property other than
cycle through the referenced objects in whatever order they are
returned? For example I have a number of reference properties to
instances where the creation date is crucial to how they are
subsequently managed. Is there a way to order the result?

class Reel(db.Model):
   name = db.StringProperty()

class Frame(db.Model):
# datetime.datetime.now() when the object is first created.
auto_now_add_prop = db.DateTimeProperty(auto_now_add=True)
# reference to the one and only reel this frame belong to
reel = db.ReferenceProperty(Reel, collection_name='frames')

I would like to order 'reel.frames' depending on the
'auto_now_add_prop' date. Is this the right way to access these
instances if date order access is frequent and  crucial?
The Frame model will have millions of instances so a query there
matching for a given Reel instance would be expensive. Ideas/advice/a
thread I haven't seen?

Alex

-- 
You received this message because you are subscribed to the Google Groups 
Google App Engine group.
To post to this group, send email to google-appeng...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.



Re: [google-appengine] Reference properties and ordering results

2010-02-24 Thread Robert Kluin
Alex,
  You can only order by properties on the model itself.  If you want
to order by a property on a referenced model, you need to include it.
So in your case you might want to add a reelName property to Frame,
then just be sure you handle updating that property when you change
the name on Reel.

Robert







On Wed, Feb 24, 2010 at 9:09 AM, Alex alexle...@googlemail.com wrote:
 Hi,
 Is it possible to do anything with a reference property other than
 cycle through the referenced objects in whatever order they are
 returned? For example I have a number of reference properties to
 instances where the creation date is crucial to how they are
 subsequently managed. Is there a way to order the result?

 class Reel(db.Model):
   name = db.StringProperty()

 class Frame(db.Model):
    # datetime.datetime.now() when the object is first created.
    auto_now_add_prop = db.DateTimeProperty(auto_now_add=True)
    # reference to the one and only reel this frame belong to
    reel = db.ReferenceProperty(Reel, collection_name='frames')

 I would like to order 'reel.frames' depending on the
 'auto_now_add_prop' date. Is this the right way to access these
 instances if date order access is frequent and  crucial?
 The Frame model will have millions of instances so a query there
 matching for a given Reel instance would be expensive. Ideas/advice/a
 thread I haven't seen?

 Alex

 --
 You received this message because you are subscribed to the Google Groups 
 Google App Engine group.
 To post to this group, send email to google-appeng...@googlegroups.com.
 To unsubscribe from this group, send email to 
 google-appengine+unsubscr...@googlegroups.com.
 For more options, visit this group at 
 http://groups.google.com/group/google-appengine?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Google App Engine group.
To post to this group, send email to google-appeng...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.



Re: [google-appengine] Reference properties and ordering results

2010-02-24 Thread Robert Kluin
Brian,
  I just re-read your thread more carefully.  I think what you want to
know is simply:
reel_frames = reel.frames.order('auto_now_add_prop.order')

  'frames' on Reel (created by the reference property from Frames) is
just a query object.

Robert








On Wed, Feb 24, 2010 at 3:01 PM, Robert Kluin robert.kl...@gmail.com wrote:
 Alex,
  You can only order by properties on the model itself.  If you want
 to order by a property on a referenced model, you need to include it.
 So in your case you might want to add a reelName property to Frame,
 then just be sure you handle updating that property when you change
 the name on Reel.

 Robert







 On Wed, Feb 24, 2010 at 9:09 AM, Alex alexle...@googlemail.com wrote:
 Hi,
 Is it possible to do anything with a reference property other than
 cycle through the referenced objects in whatever order they are
 returned? For example I have a number of reference properties to
 instances where the creation date is crucial to how they are
 subsequently managed. Is there a way to order the result?

 class Reel(db.Model):
   name = db.StringProperty()

 class Frame(db.Model):
    # datetime.datetime.now() when the object is first created.
    auto_now_add_prop = db.DateTimeProperty(auto_now_add=True)
    # reference to the one and only reel this frame belong to
    reel = db.ReferenceProperty(Reel, collection_name='frames')

 I would like to order 'reel.frames' depending on the
 'auto_now_add_prop' date. Is this the right way to access these
 instances if date order access is frequent and  crucial?
 The Frame model will have millions of instances so a query there
 matching for a given Reel instance would be expensive. Ideas/advice/a
 thread I haven't seen?

 Alex

 --
 You received this message because you are subscribed to the Google Groups 
 Google App Engine group.
 To post to this group, send email to google-appeng...@googlegroups.com.
 To unsubscribe from this group, send email to 
 google-appengine+unsubscr...@googlegroups.com.
 For more options, visit this group at 
 http://groups.google.com/group/google-appengine?hl=en.




-- 
You received this message because you are subscribed to the Google Groups 
Google App Engine group.
To post to this group, send email to google-appeng...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.



Re: [google-appengine] Reference Properties

2009-11-29 Thread 风笑雪
Of course you can use id/name to instead of reference property, but
you can get some benefit when using reference property.

One is back reference. If a reference to b, b also reference to a, you
need store a's key in b and b's key in a.
But using reference property, you can automatically get a back reference.
Once you need change the relationship, link a and c, you don't need
change a, b, c at the same time(maybe a transaction), just change a's
reference property to point to c, and everything has been done.

2009/11/29 MajorProgamming sefira...@gmail.com:
 I was wondering: isn't using reference properties a waste of space?
 Wouldn't it make more sense to store the id (assuming not using
 key_name) of the entity. After all, if the Kind is known, one can
 easily generate the full key based on that. And with a reference
 property it actually stores the _entire_ key (very long!).

 Why?

 --

 You received this message because you are subscribed to the Google Groups 
 Google App Engine group.
 To post to this group, send email to google-appeng...@googlegroups.com.
 To unsubscribe from this group, send email to 
 google-appengine+unsubscr...@googlegroups.com.
 For more options, visit this group at 
 http://groups.google.com/group/google-appengine?hl=en.




--

You received this message because you are subscribed to the Google Groups 
Google App Engine group.
To post to this group, send email to google-appeng...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.




Re: [google-appengine] Reference Properties

2009-11-29 Thread Robert Kluin
I think you can acheive the back reference by defining an instance  
method that returns a query object defined to search the other model  
for references to itself.   In fact I think that is all  
ReferenceProperty does anyway.

Try something like this:

class ModelA(db.Model):
def modelB_list(self):
if self.key():
  refs = ModelB.all()
  refs.filter('a_id_ref =', self.key().id())
  return refs
return None

class ModelB(db.Model):
 a_ref_id = db.IntegerProperty()

ma = ModelA()
ma.put()

mb1 = ModelB(a_id_ref=ma.key())
mb2 = ModelB(a_id_ref=ma.key())
db.put([mb1,mb2])


for mb in ma.modelB_list:
   print str(mb.key())


Robert


On Nov 29, 2009, at 5:17, 风笑雪 kea...@gmail.com wrote:

 Of course you can use id/name to instead of reference property, but
 you can get some benefit when using reference property.

 One is back reference. If a reference to b, b also reference to a, you
 need store a's key in b and b's key in a.
 But using reference property, you can automatically get a back  
 reference.
 Once you need change the relationship, link a and c, you don't need
 change a, b, c at the same time(maybe a transaction), just change a's
 reference property to point to c, and everything has been done.

 2009/11/29 MajorProgamming sefira...@gmail.com:
 I was wondering: isn't using reference properties a waste of space?
 Wouldn't it make more sense to store the id (assuming not using
 key_name) of the entity. After all, if the Kind is known, one can
 easily generate the full key based on that. And with a reference
 property it actually stores the _entire_ key (very long!).

 Why?

 --

 You received this message because you are subscribed to the Google  
 Groups Google App Engine group.
 To post to this group, send email to google-appengine@googlegroups.com 
 .
 To unsubscribe from this group, send email to 
 google-appengine+unsubscr...@googlegroups.com 
 .
 For more options, visit this group at 
 http://groups.google.com/group/google-appengine?hl=en 
 .




 --

 You received this message because you are subscribed to the Google  
 Groups Google App Engine group.
 To post to this group, send email to google- 
 appeng...@googlegroups.com.
 To unsubscribe from this group, send email to 
 google-appengine+unsubscr...@googlegroups.com 
 .
 For more options, visit this group at 
 http://groups.google.com/group/google-appengine?hl=en 
 .



--

You received this message because you are subscribed to the Google Groups 
Google App Engine group.
To post to this group, send email to google-appeng...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.




Re: [google-appengine] Reference Properties

2009-11-29 Thread Niklas Rosencrantz
On Sun, Nov 29, 2009 at 5:49 PM, Robert Kluin robert.kl...@gmail.com wrote:
 I think you can acheive the back reference by defining an instance
 method that returns a query object defined to search the other model
 for references to itself.   In fact I think that is all
 ReferenceProperty does anyway.

 Try something like this:

 class ModelA(db.Model):
    def modelB_list(self):
        if self.key():
          refs = ModelB.all()
          refs.filter('a_id_ref =', self.key().id())
          return refs
        return None

 class ModelB(db.Model):
     a_ref_id = db.IntegerProperty()

 ma = ModelA()
 ma.put()

 mb1 = ModelB(a_id_ref=ma.key())
 mb2 = ModelB(a_id_ref=ma.key())
 db.put([mb1,mb2])


 for mb in ma.modelB_list:
   print str(mb.key())


 Robert
i too use record.key().id() getting ok results empirically, blogged
how for dirty sitemap generator example (months b4 Agent Johnson did
it)
http://niklasro.blogspot.com/2009/08/sitemapxmlgz-generator.html

--

You received this message because you are subscribed to the Google Groups 
Google App Engine group.
To post to this group, send email to google-appeng...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.




Re: [google-appengine] Reference Properties

2009-11-29 Thread Rodrigo Moraes
On Sat, Nov 28, 2009 at 10:09 PM, MajorProgamming wrote:
 I was wondering: isn't using reference properties a waste of space?
 Wouldn't it make more sense to store the id (assuming not using
 key_name) of the entity. After all, if the Kind is known, one can
 easily generate the full key based on that. And with a reference
 property it actually stores the _entire_ key (very long!).


Storing the key or the full path is the only way to retrieve *any*
entity. Why? Because you can't generate a full key for an entity that
has ancestors using only a key name or id. You need the full path of
ancestor entities. The key is the full path encoded.

For simple and common cases (entity with no ancestor), you can surely
store simply the id or key name. But you have to keep in mind that
this won't work for any possible entity (if you store an entity with
ancestor, you can't retrieve it back).

-- rodrigo

--

You received this message because you are subscribed to the Google Groups 
Google App Engine group.
To post to this group, send email to google-appeng...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.




Re: [google-appengine] Reference Properties

2009-11-29 Thread Niklas Rosencrantz
On Sun, Nov 29, 2009 at 9:00 PM, Rodrigo Moraes
rodrigo.mor...@gmail.com wrote:
 On Sat, Nov 28, 2009 at 10:09 PM, MajorProgamming wrote:
 I was wondering: isn't using reference properties a waste of space?
 Wouldn't it make more sense to store the id (assuming not using
 key_name) of the entity. After all, if the Kind is known, one can
 easily generate the full key based on that. And with a reference
 property it actually stores the _entire_ key (very long!).


 Storing the key or the full path is the only way to retrieve *any*
 entity. Why? Because you can't generate a full key for an entity that
 has ancestors using only a key name or id. You need the full path of
 ancestor entities. The key is the full path encoded.

 For simple and common cases (entity with no ancestor), you can surely
 store simply the id or key name. But you have to keep in mind that
 this won't work for any possible entity (if you store an entity with
 ancestor, you can't retrieve it back).

 -- rodrigo

Ancestor pattern I avoid til either understood or forced there. Same
with keys, the less machinegenerated and more natural, intrinsic and
geniune identificators, the better. Welcomed proven wrong or supported
since still learning. Nick Rosencrantz

--

You received this message because you are subscribed to the Google Groups 
Google App Engine group.
To post to this group, send email to google-appeng...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.




[google-appengine] Reference Properties

2009-11-28 Thread MajorProgamming
I was wondering: isn't using reference properties a waste of space?
Wouldn't it make more sense to store the id (assuming not using
key_name) of the entity. After all, if the Kind is known, one can
easily generate the full key based on that. And with a reference
property it actually stores the _entire_ key (very long!).

Why?

--

You received this message because you are subscribed to the Google Groups 
Google App Engine group.
To post to this group, send email to google-appeng...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.




Re: [google-appengine] Reference Properties

2009-11-28 Thread Niklas Rosencrantz
On Sun, Nov 29, 2009 at 12:09 AM, MajorProgamming sefira...@gmail.com wrote:
 I was wondering: isn't using reference properties a waste of space?
 Wouldn't it make more sense to store the id (assuming not using
 key_name) of the entity. After all, if the Kind is known, one can
 easily generate the full key based on that. And with a reference
 property it actually stores the _entire_ key (very long!).

 Why?
We do waste space to quicken dev time and rapid prototyping. I call it
a tradeoff, know ways to easy storage use several halves that view
won't react to, making 100 created object 50 and 25 etc, priotitizing
security, stability and views top, optimizations last.

--

You received this message because you are subscribed to the Google Groups 
Google App Engine group.
To post to this group, send email to google-appeng...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.




[google-appengine] Reference Properties in GQL Queries

2009-06-19 Thread Alfonso Lopez

Is there any way to give a WHERE conditional values from a reference
property?  Something to this affect

SELECT * FROM some_table WHERE referenceprop.name='yay'

Where 'name' is a property of the referenced Kind?

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Google App Engine group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~--~~~~--~~--~--~---