I use
my_classalias = pyamf.register_class(mymodel, mymodel._meta.object_name)
to make my django model into AMF serialized objects.
But the problem is mymodel contains a auto created pk field called id
, but the Flash/Flex client can't accept such field, is there a way to remove that in PyAMF ClassAlias?
Thanks in advance!
Here is my own solution:
m = my_model
ka = pyamf.register_class(m, m._meta.object_name)
ka.exclude_attrs = ['field1', 'field2']
or alternatively, in your models.py
class my_model(models.Model):
field1 = IntegerField()
field2 = TextField()
class __amf__:
exclude = ('field1', )
Note there is a unpatched bug in PyAMF for the m2m fields, you may have to manually edit file pyamf/adapters/_django_db_models_base.py
, line 168
:
for name, relation in self.relations.iteritems():
if name in self.exclude_attrs:
continue
if '_%s_cache' % name in obj.__dict__:
attrs[name] = getattr(obj, name)
Hope this helps someone who has the same problem with me.