如何在 Django/PyAMF 和 Flex 之间映射字段名称?
例如,使用我的 UserProfile 模型:
class UserProfile(models.Model):
user = models.ForeignKey( User, unique=True )
blurb = models.CharField( max_length=200, null=True, blank=True )
public = models.BooleanField( default=True )
...
因此,我最终得到一个名为“public”的字段。这在 ActionScript 中并不适用,因为它是一个关键字。更改很烦人,因为它已融入 django-profile 包中的多个功能层中。因此,我被迫在 Flex 端重命名它:
[RemoteClass(alias="...")]
[Bindable]
public class UserProfile
{
public function UserProfile()
{
}
public var id:int;
public var blurb:String;
public var _public:Boolean;
...
在事务的任意一侧,我可以在哪里声明“远程字段 public 转换为本地字段 _public”?我在 PyAMF 方面对 ClassAliases 进行了一些混乱,但它很快就变得混乱,并且没有关于如何很好地做到这一点的文档。 Flex 方面的文档似乎表明有一个我可以覆盖的“处理传入请求”处理程序,但我认为它是在已经填充 com 对象中的字段之后发生的,因此将它们放在地板上,因为适当的字段不存在,给我留下了一堆:
ReferenceError: Error #1056: Cannot create property
在 Flex 跟踪中......
For example, using my UserProfile model:
class UserProfile(models.Model):
user = models.ForeignKey( User, unique=True )
blurb = models.CharField( max_length=200, null=True, blank=True )
public = models.BooleanField( default=True )
...
Thus, I end up with a field called "public". This doesn't jive in ActionScript because it's a keyword. It's annoying to change because it's baked into several layers of functionality in the django-profile package. So, I'm forced to rename it on the Flex side:
[RemoteClass(alias="...")]
[Bindable]
public class UserProfile
{
public function UserProfile()
{
}
public var id:int;
public var blurb:String;
public var _public:Boolean;
...
Where, on either side of the transaction, can I state "remote field public translates to local field _public"? I messed around a bit with ClassAliases on the PyAMF side but it got messy quickly and there's no documentation on how to do this nicely. And the documentation on the Flex side seems to indicate that there's a "process the incoming request" handler that I can override, but I think it occurs after already populating the fields in the com object, thus dropping them on the floor, since the appropriate field is not there, and leaving me with a bunch of:
ReferenceError: Error #1056: Cannot create property
in the Flex trace...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了支持这一点,PyAMF 需要提供字段之间的同义词映射。在那之前,您可以使用 IExternalizable (尽管笨拙) ):
使用相应的 Flex 代码:
注意我还没有测试上面的代码,但原则上应该可以工作。
顺便说一句,您能否更详细地了解文档中令人困惑的地方?我很想让新用户尽可能清楚地了解这一点。
In order to support this, PyAMF needs to provide a synonym mapping between fields. Until then, you could use IExternalizable (although clumsily):
With the corresponding Flex code:
Note I haven't tested the above code, but should work in principle.
Btw, can you go into greater detail about what was confusing about the documentation? I would love to make that as clear possible for new users.