>
> I really tried hard to understand your problem, but then my brain
> started to leak out of my ears and I had to stop. :-(
>
> Could you post an example of how all these models are related? You seem
> to have Relmodl2, model2 and model1 and I'm not sure what all the
> linkages are.
>
> I think what you are asking is why does the reverse end of a ForeignKey
> show up in get_all_related_objects(), but the forward direction does
> not. If that is the question, the forward direction (the ForeignKey
> field itself), is just an object of class ForeignKey in the _meta.fields
> attribute on the model it is defined on. So you need to inspect the
> class types in _meta.fields to see which are the forwards relations.
>
> If that isn't your question, I apologise and ask only for a simple
> example to illustrate the problem.
>
> Regards,
> Malcolm



sorry, shouldn't post so late I guess...

I would like to make a list of allowable arguments for filter
to supply that as a selection list on a search page.

so I have to get a list of 'model__field' like strings
derived from  models (models.get_all_models())


class Poll(models.Model):
    question = models.CharField(maxlength=200)
    pub_date = models.DateTimeField('date published')


class Choice(models.Model):
    poll = models.ForeignKey(Poll)
    choice = models.CharField(maxlength=200)
    votes = models.IntegerField()

relfieldargs = ['%s__%s' % (m.model._meta.module_name,f.name)
          for m in Poll._meta.get_all_related_objects()
          for f in m.model._meta.fields ]

relfieldargs:
['choice__id', 'choice__poll', 'choice__choice', 'choice__votes']

I can use these as (part of)arguments for filter

Poll.objects.filter(choice__votes__gt=0)


but the other way around doesn't work (from Choice->Poll)

relfieldargs = ['%s__%s' % (m.model._meta.module_name,f.name)
          for m in Choice._meta.get_all_related_objects()
          for f in m.model._meta.fields ]

relfieldargs:
[]

so I need some other way to get those.


Now you seem to say that the answer is in here,


In [18]: [f for f in Choice._meta.fields]
Out[18]:
[<django.db.models.fields.AutoField object at 0xb7c87bcc>,
 <django.db.models.fields.related.ForeignKey object at 0xb7c8744c>,
 <django.db.models.fields.CharField object at 0xb7c8772c>,
 <django.db.models.fields.IntegerField object at 0xb7c879ac>]

which I can see. but how do a make an expression to test for
foreignkey
(except for  'fields.related' in `f` which seems a bit clumsy)


and then of course I would like to find the 2nd (or higher) order
cases too

'model1__model2__field_of_model2'

any simple ways to find those?

thanks for your help.


abe


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to