PyAMF、Django和Python的“属性”特性存在问题

2024-05-15 05:11:47 发布

您现在位置:Python中文网/ 问答频道 /正文

到目前为止,我已经成功地使用PyAMF在Flex前端和Django后端之间进行通信。不过,我想我遇到了一个bug。下面的示例(强调单词“example”)演示了(潜在的)bug:

我的Flex应用程序包含以下VO:

package myproject.model.vo
{
    [Bindable]
    [RemoteClass(alias="myproject.models.Book")]

    public class BookVO
    {
        public var id:int;
        public var title:String;
        public var numberOfOddPages:int;
    }
}

我的Django应用程序包含以下模型:

^{pr2}$

当我尝试检索要在DataGrid中显示的book对象时,这些书将按预期显示在网格中。但是,“numberOfFoddPages”始终设置为0。我甚至尝试用默认值显式设置此属性(即“numberOfOddPages=100”),以查看我的“\u get_number_of_odd_pages()”方法是否有错误。不幸的是,它产生了相同的结果:VO中的值保持为0。在

有人知道我做错了什么吗?在


Tags: django应用程序示例packageexamplevarmyprojectpublic
2条回答

我刚收到PyAMF首席开发人员的以下回复。这绝对是个bug:

This is a bug in the way the Django adapter handles non models.fields.* properties.

If I do:

import pyamf

class Book(object):    
def _get_number_of_odd_pages(self):
  return 52

numberOfOddPages = property(_get_number_of_odd_pages)

pyamf.register_class(Book, 'Book')

encoded = pyamf.encode(Book()).getvalue() 
print pyamf.decode(encoded).next().numberOfOddPages

Then i get the correct values of 52.

I have created a ticket for this and will look into getting a patch a little later.

Cheers,

Nick

更新:Nick已经修复了这个bug,它将在pyamf0.4.1中发布(应该在本周末发布)。在

一点也不。在

您认为错误是来自Django还是来自Flex?首先可以在Flex中跟踪AMF对象。如果那里的值是allready 0,那么仔细看看PyAMF是怎么做的。在

相关问题 更多 >

    热门问题