Get Objects With Date Greater Than Today Or Empty Date
I need to select all model objects with date field greater than today date OR date field empty. I have following code: @login_required def event_new(request, person_uuid=None):
Solution 1:
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))
Post a Comment for "Get Objects With Date Greater Than Today Or Empty Date"