[Django]-How to get all objects of a Parent model of which foreign key exist in child model in Django?

5👍

If I understand what you need correctly, it should be something like this:

Parent.objects.filter(
    child__isnull=False,
    child__timeStamp__gt=datetime.strptime(
        '2016-01-01 00.00.00',
        '%Y-%m-%d %H.%M.%S'
    )
)

This fetches all Parent objects for which there is a child whose timestamp is later than 2016/01/01.

Leave a comment