[Django]-How to filter objects with date > today or empty date from a Model in Django?

38👍

Use Q.

from django.db.models import Q

@login_required
def event_new(request, person_uuid=None):
    today = datetime.datetime.today()
    #valid_until may be empty
    profile = Profile.objects.filter(company=request.user.company).filter(Q(valid_until__gte=today)|Q(valid_until=None))

Leave a comment