English 中文(简体)
Django, 获得了完全序列化的物体。 许多到许多关系的所有财产
原标题:Django, get fully serialized object. All properties from many to many relationships

I m 寻求一种方式,使整个物体与所有物体的关系相序列。 我似乎只能从现在的序列器那里获得主要钥匙。

这是我的模式:

class Action(models.Model):
    name = models.CharField( Action Name , max_length=250, unique=True)
    message = models.TextField( Message , blank=True, null=True)
    subject = models.CharField( Subject , max_length=40, null=True)
    recipient = models.ManyToManyField( Recipient , blank=True, null=True)

    def __str__(self):
            return unicode(self.name).encode( utf-8 )

    def __unicode__(self):
            return unicode(self.name)

class Recipient(models.Model):
    address = models.EmailField( Address , max_length=75, unique=True)
    businessHours = models.BooleanField( Business Hours Only , default=False)

    def __str__(self):
            return unicode(self.address).encode( utf-8 )

    def __unicode__(self):
            return unicode(self.address)

我在这里管理着序号:

all = serializers.serialize( xml , list(Action.objects.select_related().all()))

如果我印刷了所有产出,只列出受援国的主要关键。

<field type="CharField" name="subject">On The Road Productions</field>
<field to="sla.recipient" name="recipient" rel="ManyToManyRel">
<object pk="29"></object>
</field></object>
<object pk="11" model="sla.action">
<field type="CharField" name="name">On The Road Productions</field>
<field type="TextField" name="message">

我还需要相关接收人的所有财产。 我如何能够做到这一点?

edit - 我发现这件事

我在Xml_serializer.py中发现,但我并不肯定如何加以修改。

def handle_m2m_field(self, obj, field):
    """
    Called to handle a ManyToManyField. Related objects are only
    serialized as references to the object s PK (i.e. the related *data*
    is not dumped, just the relation).
    """
    if field.creates_table:
        self._start_relational_field(field)
        for relobj in getattr(obj, field.name).iterator():
            self.xml.addQuickElement("object", attrs={"pk" :  smart_unicode(relobj._get_pk_val())})
        self.xml.endElement("field")
问题回答

有人建议研究django-piston的内部。

采用 d戈-皮斯顿语,这不会引起任何问题,因此该法典可读。 .。





相关问题
How to get two random records with Django

How do I get two distinct random records using Django? I ve seen questions about how to get one but I need to get two random records and they must differ.

Moving (very old) Zope/Plone Site to Django

I am ask to move data from a (now offline) site driven by Plone to a new Django site. These are the version informations I have: Zope Version (unreleased version, python 2.1.3 ) Python Version 2.1....

Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

Flexible pagination in Django

I d like to implement pagination such that I can allow the user to choose the number of records per page such as 10, 25, 50 etc. How should I go about this? Is there an app I can add onto my project ...

is it convenient to urlencode all next parameters? - django

While writing code, it is pretty common to request a page with an appended "next" query string argument. For instance, in the following template code next points back to the page the user is on: &...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

热门标签