Skip to content Skip to sidebar Skip to footer

Django - How To Use A Filter With A Foreign Key Field?

I'm trying to do this: LogEntry.objects.filter(content_type='visitor') Where LogEntry is my model and content_type is a ForeignKey field pointing to another table with field id, a

Solution 1:

Ahh, found it in another SO answer. Weird it didn't seem to be documented. Or I just skimmed over it.

Answer:

LogEntry.objects.filter(content_type__name='visitor') 

Post a Comment for "Django - How To Use A Filter With A Foreign Key Field?"