Hi guys,

as I understand, m2m with intermediate model and ordering is a bit (at
least) tricky:

https://code.djangoproject.com/ticket/11850

I need the ordering in my serialised data. The serialiser must of
course be independent of any names, so I use introspection so far.
Code so far is here:

def serialise(obj):

    serialised_data = {}
    serialised_data["item_type"] = obj._meta.object_name

    fields = obj._meta.fields
    for field in fields:
        name = field.name
        value = field.value_from_object(obj)
        serialised_data[name] = value

Now, I know I can get the m2m fields with:

    for many_to_many in many_to_manys:
        field_name = many_to_many.name

But then I'm stuck. How can I get the ordering, which is defined in
the intermediate table (the "through" model)? I couldn't use the
reverse trick (in the example in the Django ticket, link above) like
this:

beatles.membership_set.all()

as I would need to know the name in advance. Or is there some
introspection magic that gets me the reverse name, which can of course
be user defined in the intermediate table by "related_name"?

Hm, hm, hm, I'm stuck at this ordering problem for over a week. Any
help is desperately ;-) appreciated.

Cheers,

Jan
        rel_objs = getattr(obj, field_name).all()

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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.

Reply via email to