On Sun, 2008-03-30 at 14:08 -0700, jurian wrote: > I'm quite new to Django source so I wanted to get some advice on some > additions I tought of making to the code base. > > My final goal is to get a list of names of the models related to a > certain model (perhaps there is a very simple way of doing this I > don't know of). > > First I though of adding a 'get_all_related_models' method to > django.db.models.options, but then I realized that I won't be able to > access the '_meta' attribute from the page templates, so I though of > changing it to 'get_all_related_model_names'. > > Please let me know if I'm on the right track, or if I'm totally > missing something here.
We already have a fairly straightforward way to get access to all the related fields -- related "models" is not fine-grained enough for most purposes, since there can easily be multiple fields on Model A relating to Model B. We use that functionality in querysets for example, when you specify an invalid field: the error tells you which field names are legal. Start from there and you could write a simple function like this for your own purposes that only includes reverse relations. I'm not sure there's any need for it to go into Django's core, but it can be implemented without needing any core changes, so you should be able to incorporate it into your own projects easily enough. Malcolm -- The hardness of butter is directly proportional to the softness of the bread. http://www.pointy-stick.com/blog/ --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
