W dniu 20.03.2012 22:00, Łukasz Rekucki pisze:
        1) The Meta.structure things looks like a non-starter to me. It's
a DSL inside a DSL. I'm also not sure what it actually does - you
already have all those @attribute decorators, why repeat their names
in some string?
    One of my principle was to let user define any possible structure.
Ex
<object>
<a>
<b>
<c>
<name>Django</name>
</c>
</b>
</a>
</object>

1. With Meta.structure you can do:
def name
    return Django
structure="a[b[c[name__field]]]

2. Without:
def a
    return BFieldSerializer
class BFieldSerializer
    def b
        ...

You see my point? I agree that second solution is more elegant but first is a lot faster. Question is that someone actually want/need to define structure tree like this.

Ex2.

<object>
<model_field1>...
<model_field2>...
<special_model_fields>
<model_field_3>
<model_field_4>
</special_model_fields>
<object>

1. structure="model_field1__field model_field2__field special_model_fields{model_field3__field model_field4__field}" or structure="__fields special_model_fields{model_field3__field model_field4__field}"

2. Even if model_field1/2 will be automaticaly in right place what to do with 3/4 ?
def special_model_fields
    return {'model_field_3' : model_field_3, model... }

Hmm, I want to prove that structure will be better in this case but come up with above idea :) If Serializers methods can returns base type objects, FieldSerializers, [] and {} we can define anything :) And it's a lot better than structure!
Must rewrite my proposal :)



     3) Did you thought about splitting the serialization process in
two parts (dehydration + presentation)? This is what most REST
frameworks do. First you serialize the objects into Python native
types, then render it to any format.


Yes, in my solution anything at the end of first phaze will be Python base type, BaseFieldSerialize subclass or BaseModelSerializer subclass with resolved Meta.structure. If I remove Meta.structure it will be even simplier. I can resolve Base(Model/Field)Serializer only when i know to what format it will be serialized.



--
Piotr Grabowski

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

Reply via email to