python - PyAMF、Django 和 Python 的 "property"功能问题

标签 python django apache-flex flex3 pyamf

到目前为止,我已经成功地使用 PyAMF 在我的 Flex 前端和我的 Django 后端之间进行通信。但是,我相信我遇到了一个错误。以下示例(强调“示例”一词)演示了(潜在的)错误:

我的 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 应用包含以下模型:

class Book(models.Models):
    title = models.CharField(max_length=20)

    def _get_number_of_odd_pages(self):
        #some code that calculates odd pages
       return odd_page_total

    numberOfOddPages = property(_get_number_of_odd_pages)

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

有没有人知道我可能做错了什么?

最佳答案

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

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 已经修复了这个错误,它将在 PyAMF 0.4.1 中发布(应该在本周末发布)。

关于python - PyAMF、Django 和 Python 的 "property"功能问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/558926/

相关文章:

java - Flex 和 Java 集成

python - Python 适用于专注于科学计算的算法吗?

从字符串中提取可能日期的 Python 模块?

python - 如何在heroku中使用现有的git存储库

python - Django:类型为 'datetime' 的对象不是 JSON 可序列化的

apache-flex - 有没有办法结合 Ogre3d 的 Hikari 和 BlazeDS?

android - 秒获取数据,想计算时分秒

Python If 语句使用 'and' 和 'in'

python - 编写一个自定义 Django BaseCommand 类来记录命令详细信息

python - MySQLdb OperationalError : (2004, "Can' t 创建 TCP/IP 套接字 (24)")