I think you've got something else wrong. Either way should work.
Robert
class Test(db.Model):
ref = db.ReferenceProperty()
t1 = Test(key_name="one")
t1_key = t1.put()
t2 = Test(key_name="two")
t2_key = t2.put()
# Make some entities with references.
t3 = Test(key_name="three", ref=t1)
t3_key = t3.put()
t4 = Test(key_name="four", ref=t2_key)
t4_key = t4.put()
# Check they were saved.
t3 = Test.get_by_key_name("three")
print 'three: ', str(t3.ref.key().name())
t4 = Test.get_by_key_name("four")
print 'four: ', str(t4.ref.key().name())
# Change the refs.
t3.ref = t2_key
t3.put()
t4.ref = t1
t4.put()
# Re-check.
t3 = Test.get_by_key_name("three")
print 'three: ', str(t3.ref.key().name())
t4 = Test.get_by_key_name("four")
print 'four: ', str(t4.ref.key().name())
On Sun, Nov 21, 2010 at 07:53, Haulyn R. Jason <[email protected]> wrote:
> Hi, I am trying to solve the problem, but I am confused by the key. Should
> anybody help me to check these code?
> I want to update a reference property, I want to change the shop from shop1
> to shop2 for custom. I am not sure which way is right:
> custom.shop = shop2
> custom.put()
> or
> custom.shop = shop2.key()
> custom.put()
> I tried these two ways, but not work.
> Thanks.
>
>
>
> On Sun, Nov 21, 2010 at 3:13 PM, Haulyn R. Jason <[email protected]>
> wrote:
>>
>> Hi,
>> I am writing something code to create a model, and then update it. I have
>> a referenced property, it works well on create function, but it does not
>> work in update function. The code is simple as follow:
>>
>> r = Information.get(self.params.get('id'))
>> r.shop = Shop.get(self.params.get('shop'))
>> for prop in Information.properties():
>> if prop in self.params:
>> if prop is 'end_date':
>> r.end_date =
>> datetime.strptime(self.params.get('end_date',None),'%Y/%m/%d')
>> else:
>> setattr(r, prop, self.params.get(prop))
>> r.save()
>> self.redirect('/information/show/%s' % (r.key()))
>> Other properties are updated, but I can not update r.shop, I just tried to
>> assign shop2 instead of shop1 for my Information model.
>> Are there something I missed?
>>
>> Thanks!
>> slackdot.com
>> Location:Room 807,QiLuRuanJianDaSha Qilu Software Park
>> No. 1 Shunhua Rd High-Tech Development Zone
>> Jinan, China 250101
>> Website: http://slackdot.com
>> Mobile: +86 15854103759
>> Haulyn Jason
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> 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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine?hl=en.