Get objects with date greater than today or empty date

后端 未结 1 753
情深已故
情深已故 2021-02-07 06:46

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(requ         


        
1条回答
  •  盖世英雄少女心
    2021-02-07 06:52

    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))
    

    0 讨论(0)
提交回复
热议问题