Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 Dec. 20, 2010 15:13:53

gregory s.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Complex serialization from models


Hi all,

I'm searching a simple way to generate xml from my models, and a
simple use of serializers can do this for me.
But my models are defined with ForeignKey and ManyToManyField...
The xml generated shows me only key values of these field.

Is there a simple way to catch any other field value than "id",
related to ForeignKey or ManyToManyField?
I mean with this example:

class Shirt(models.Model):
color = ManyToManyField(Color)
name = models.CharField(max_length=255)

class Color(models.Model):
value = models.CharField(max_length=6)
....

to generate this kind of xml (not really this one but the same tree
structure)

<shirt name="fdkfjb">
<color>000000</color>
<color>00EE00</color>
<color>0000FF</color>
</shirt>

and NOT (as i try to explain):

<shirt name="fdkfjb">
<color>1</color>
<color>2</color>
<color>3</color>
</shirt>

Thanks for your answer

Greg







--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 Dec. 21, 2010 12:19:22

gregory s.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Complex serialization from models


Nobody has a quick answer ?

On Dec 20, 4:11 pm, gregory semah <gregory.se...@gmail.com> wrote:
> Hi all,
>
> I'm searching a simple way to generate xml from my models, and a
> simple use of serializers can do this for me.
> But my models are defined with ForeignKey and ManyToManyField...
> The xml generated shows me only key values of these field.
>
> Is there a simple way to catch any other field value than "id",
> related to ForeignKey or ManyToManyField?
> I mean with this example:
>
> class Shirt(models.Model):
>        color = ManyToManyField(Color)
>        name = models.CharField(max_length=255)
>
> class Color(models.Model):
>        value = models.CharField(max_length=6)
>        ....
>
> to generate this kind of xml (not really this one but the same tree
> structure)
>
> <shirt name="fdkfjb">
>      <color>000000</color>
>      <color>00EE00</color>
>      <color>0000FF</color>
> </shirt>
>
> and NOT (as i try to explain):
>
> <shirt name="fdkfjb">
>      <color>1</color>
>      <color>2</color>
>      <color>3</color>
> </shirt>
>
> Thanks for your answer
>
> Greg

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#3 Dec. 21, 2010 12:24:53

Konrad D.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Complex serialization from models


On 21 December 2010 13:19, gregory semah <gregory.se...@gmail.com> wrote:
> Nobody has a quick answer ?
>

It looks like xml serialisation wasn't designed to be customisable in
the way you need. If I were you, I'd look around the code and see what
I could reuse from there.

Konrad

> On Dec 20, 4:11 pm, gregory semah <gregory.se...@gmail.com> wrote:
>> Hi all,
>>
>> I'm searching a simple way to generate xml from my models, and a
>> simple use of serializers can do this for me.
>> But my models are defined with ForeignKey and ManyToManyField...
>> The xml generated shows me only key values of these field.
>>
>> Is there a simple way to catch any other field value than "id",
>> related to ForeignKey or ManyToManyField?
>> I mean with this example:
>>
>> class Shirt(models.Model):
>>        color = ManyToManyField(Color)
>>        name = models.CharField(max_length=255)
>>
>> class Color(models.Model):
>>        value = models.CharField(max_length=6)
>>        ....
>>
>> to generate this kind of xml (not really this one but the same tree
>> structure)
>>
>> <shirt name="fdkfjb">
>>      <color>000000</color>
>>      <color>00EE00</color>
>>      <color>0000FF</color>
>> </shirt>
>>
>> and NOT (as i try to explain):
>>
>> <shirt name="fdkfjb">
>>      <color>1</color>
>>      <color>2</color>
>>      <color>3</color>
>> </shirt>
>>
>> Thanks for your answer
>>
>> Greg
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
>http://groups.google.com/group/django-users?hl=en.
>
>

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#4 Dec. 21, 2010 12:34:48

Dan F.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Complex serialization from models


On 21 Dec 2010, at 12:19, gregory semah wrote:

> Nobody has a quick answer ?
>

Take a look at Django's natural key support - it allows you to control what's
serialized for fk references.

Cheers,
Dan

> On Dec 20, 4:11 pm, gregory semah <gregory.se...@gmail.com> wrote:
>> Hi all,
>>
>> I'm searching a simple way to generate xml from my models, and a
>> simple use of serializers can do this for me.
>> But my models are defined with ForeignKey and ManyToManyField...
>> The xml generated shows me only key values of these field.
>>
>> Is there a simple way to catch any other field value than "id",
>> related to ForeignKey or ManyToManyField?
>> I mean with this example:
>>
>> class Shirt(models.Model):
>> color = ManyToManyField(Color)
>> name = models.CharField(max_length=255)
>>
>> class Color(models.Model):
>> value = models.CharField(max_length=6)
>> ....
>>
>> to generate this kind of xml (not really this one but the same tree
>> structure)
>>
>> <shirt name="fdkfjb">
>> <color>000000</color>
>> <color>00EE00</color>
>> <color>0000FF</color>
>> </shirt>
>>
>> and NOT (as i try to explain):
>>
>> <shirt name="fdkfjb">
>> <color>1</color>
>> <color>2</color>
>> <color>3</color>
>> </shirt>
>>
>> Thanks for your answer
>>
>> Greg
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
>http://groups.google.com/group/django-users?hl=en.
>

--
Dan Fairs | dan.fa...@gmail.com | www.fezconsulting.com


--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

Board footer

Moderator control

Enjoy the 21st of August
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support