Hi all !

So this might be a stupid idea, or it might have been answered
before ... actually it seems so obvious to me that you have probably
thought of it before and rejected it !!! But let's try ...

I was wondering, why isn't there a user API for introspecting models ?

OK, there is an API, through '_meta', which is not documented (unless
you read the source), which is not addressed to users, and is
therefore likely to change, and therefore unreliable.

On the other hand, there are a lot of cases where introspecting your
models enables much more dryer code (ModelForm, admin, but also lots
of 3rd-party applications, APIs - serialization, automatic templating,
and so on). So why not helping the users to do that ?

I am myself working on some serializers and I need a list of ALL the
fields, (ALL as in "as seen by a user"). A lot of things are actually
not straight-forward, for example : many2many handled separately
(which as a user you don't really care about), MTI which messes-up
everything by adding pointer fields (which as a user you don't really
care about either), and hiding the real pk.

So, right now introspecting models is pretty much detective work,
while I think providing a simple interface for it could enable a lot
of powerful things to be written.

Does this make sense ? Any thoughts ?

Sébastien

PS : here is the code I came up with to return a dict of all fields
(like I said ... detective work) : http://dpaste.com/hold/619453/
PS3 : I can totally work on that / submit a patch if some are
interested

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

Reply via email to