I have the following Django and Flex code:
Django
class Author(models.Model): name = models.CharField(max_length=30) class Book(models.Model): title = models.CharField(max_length=30) author = models.ForeignKeyField(Author)
Flex
package com.myproject.models.vo { [Bindable] [RemoteClass(alias='myproject.models.Book')] public class BookVO { public var id:int; public var title:String; public var author: AuthorVO; } }
As you can see in this example, Author is a foreign key in my Book model. Now I’d like to acccess the author’s name when I call my BookVO in Flex. As such, I’d expect code like the following to work, but ‘author_name’ results in a null:
var book = new BookVO(); var author_name = book.author.name;
I realize I could call an AuthorVO directly, but the crux of this question is how can you retrieve foreign-keyed values using Flex when your VOs are bound to a remote object? I’m currently using PyAMF to bridge the gap between Flex and Django, but I’m not sure that’s relevant.
Ok, Here’s an example…
Model:
Here’s my amfgateway.py
and here’s my Actionscript for the receiving side of the AMF call:
The evt._who_cache.lname is populated with the select_related() and missing when the select related is missing. If I get rid of the select_related() call, then I see the error:
You must be trying a different technique with your RemoteClass… so the select_related might not be the problem at all… (otherwise my first answer wouldn’t have gotten negged.) The rest is up to you.