Django: Having problem when calculate differences between today's date and date in database












2















I have an object name Device with 'trandate' attribute.



I want to get differences between today's date and database date.



And then calculate the number of devices where the device's inactive_days is greater than 31.



Here is my code.



todays_date = datetime.now()
trandate = request.GET.get('devc_trandate')
inactive_days = todays_date - datetime(trandate)
inactive_devices = Cust.objects.values('name').annotate(inact_devc_count = Count('devc',filter=Q(inactive_days__gte=31)))


But I got an error.



an integer is required (got type NoneType)


Traceback:



File "C:PythonPython36libsite-packagesdjangocorehandlersexception.py" in inner
34. response = get_response(request)

File "C:PythonPython36libsite-packagesdjangocorehandlersbase.py" in _get_response
126. response = self.process_exception_by_middleware(e, request)

File "C:PythonPython36libsite-packagesdjangocorehandlersbase.py" in _get_response
124. response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "C:Userscustomersviews.py" in DevSummary_more
178. inactive_days = todays_date - datetime(trandate)

Exception Type: TypeError at /summary/more/
Exception Value: an integer is required (got type NoneType)









share|improve this question

























  • can you please share your full traceback?

    – ruddra
    Nov 13 '18 at 4:26
















2















I have an object name Device with 'trandate' attribute.



I want to get differences between today's date and database date.



And then calculate the number of devices where the device's inactive_days is greater than 31.



Here is my code.



todays_date = datetime.now()
trandate = request.GET.get('devc_trandate')
inactive_days = todays_date - datetime(trandate)
inactive_devices = Cust.objects.values('name').annotate(inact_devc_count = Count('devc',filter=Q(inactive_days__gte=31)))


But I got an error.



an integer is required (got type NoneType)


Traceback:



File "C:PythonPython36libsite-packagesdjangocorehandlersexception.py" in inner
34. response = get_response(request)

File "C:PythonPython36libsite-packagesdjangocorehandlersbase.py" in _get_response
126. response = self.process_exception_by_middleware(e, request)

File "C:PythonPython36libsite-packagesdjangocorehandlersbase.py" in _get_response
124. response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "C:Userscustomersviews.py" in DevSummary_more
178. inactive_days = todays_date - datetime(trandate)

Exception Type: TypeError at /summary/more/
Exception Value: an integer is required (got type NoneType)









share|improve this question

























  • can you please share your full traceback?

    – ruddra
    Nov 13 '18 at 4:26














2












2








2








I have an object name Device with 'trandate' attribute.



I want to get differences between today's date and database date.



And then calculate the number of devices where the device's inactive_days is greater than 31.



Here is my code.



todays_date = datetime.now()
trandate = request.GET.get('devc_trandate')
inactive_days = todays_date - datetime(trandate)
inactive_devices = Cust.objects.values('name').annotate(inact_devc_count = Count('devc',filter=Q(inactive_days__gte=31)))


But I got an error.



an integer is required (got type NoneType)


Traceback:



File "C:PythonPython36libsite-packagesdjangocorehandlersexception.py" in inner
34. response = get_response(request)

File "C:PythonPython36libsite-packagesdjangocorehandlersbase.py" in _get_response
126. response = self.process_exception_by_middleware(e, request)

File "C:PythonPython36libsite-packagesdjangocorehandlersbase.py" in _get_response
124. response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "C:Userscustomersviews.py" in DevSummary_more
178. inactive_days = todays_date - datetime(trandate)

Exception Type: TypeError at /summary/more/
Exception Value: an integer is required (got type NoneType)









share|improve this question
















I have an object name Device with 'trandate' attribute.



I want to get differences between today's date and database date.



And then calculate the number of devices where the device's inactive_days is greater than 31.



Here is my code.



todays_date = datetime.now()
trandate = request.GET.get('devc_trandate')
inactive_days = todays_date - datetime(trandate)
inactive_devices = Cust.objects.values('name').annotate(inact_devc_count = Count('devc',filter=Q(inactive_days__gte=31)))


But I got an error.



an integer is required (got type NoneType)


Traceback:



File "C:PythonPython36libsite-packagesdjangocorehandlersexception.py" in inner
34. response = get_response(request)

File "C:PythonPython36libsite-packagesdjangocorehandlersbase.py" in _get_response
126. response = self.process_exception_by_middleware(e, request)

File "C:PythonPython36libsite-packagesdjangocorehandlersbase.py" in _get_response
124. response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "C:Userscustomersviews.py" in DevSummary_more
178. inactive_days = todays_date - datetime(trandate)

Exception Type: TypeError at /summary/more/
Exception Value: an integer is required (got type NoneType)






django






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 4:28







Yvonne

















asked Nov 13 '18 at 4:14









YvonneYvonne

615




615













  • can you please share your full traceback?

    – ruddra
    Nov 13 '18 at 4:26



















  • can you please share your full traceback?

    – ruddra
    Nov 13 '18 at 4:26

















can you please share your full traceback?

– ruddra
Nov 13 '18 at 4:26





can you please share your full traceback?

– ruddra
Nov 13 '18 at 4:26












2 Answers
2






active

oldest

votes


















1














The error shows that the 'devc_trandate' is None.



There is another way to do this:



todays_date = datetime.now()
inactive_date = todays_date - timedelta(days=31)
inactive_devices = Cust.objects.values('name').annotate(inact_devc_count = Count('devc',filter=Q(devc__trandate__lt=inactive_date)))


Since you want to get the number of devices where the device's inactive_days is greater than 31, you can do today - 31 to get the date, then you can get the inactive device by checking which trandate is lesser than the inactive date.






share|improve this answer































    0














    Looks like there is no 'devc_trandate' parameter in the request. So when creating datatime instance its getting None giving you that error.



    Also to create datatime object you need at least 3 parameter for year, month and day. Don't think you can pass string representation of datetime to create an object. You may want to use strptime() method to parse string into datetime object.






    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53273708%2fdjango-having-problem-when-calculate-differences-between-todays-date-and-date%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      The error shows that the 'devc_trandate' is None.



      There is another way to do this:



      todays_date = datetime.now()
      inactive_date = todays_date - timedelta(days=31)
      inactive_devices = Cust.objects.values('name').annotate(inact_devc_count = Count('devc',filter=Q(devc__trandate__lt=inactive_date)))


      Since you want to get the number of devices where the device's inactive_days is greater than 31, you can do today - 31 to get the date, then you can get the inactive device by checking which trandate is lesser than the inactive date.






      share|improve this answer




























        1














        The error shows that the 'devc_trandate' is None.



        There is another way to do this:



        todays_date = datetime.now()
        inactive_date = todays_date - timedelta(days=31)
        inactive_devices = Cust.objects.values('name').annotate(inact_devc_count = Count('devc',filter=Q(devc__trandate__lt=inactive_date)))


        Since you want to get the number of devices where the device's inactive_days is greater than 31, you can do today - 31 to get the date, then you can get the inactive device by checking which trandate is lesser than the inactive date.






        share|improve this answer


























          1












          1








          1







          The error shows that the 'devc_trandate' is None.



          There is another way to do this:



          todays_date = datetime.now()
          inactive_date = todays_date - timedelta(days=31)
          inactive_devices = Cust.objects.values('name').annotate(inact_devc_count = Count('devc',filter=Q(devc__trandate__lt=inactive_date)))


          Since you want to get the number of devices where the device's inactive_days is greater than 31, you can do today - 31 to get the date, then you can get the inactive device by checking which trandate is lesser than the inactive date.






          share|improve this answer













          The error shows that the 'devc_trandate' is None.



          There is another way to do this:



          todays_date = datetime.now()
          inactive_date = todays_date - timedelta(days=31)
          inactive_devices = Cust.objects.values('name').annotate(inact_devc_count = Count('devc',filter=Q(devc__trandate__lt=inactive_date)))


          Since you want to get the number of devices where the device's inactive_days is greater than 31, you can do today - 31 to get the date, then you can get the inactive device by checking which trandate is lesser than the inactive date.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 14 '18 at 1:34









          YvKlYvKl

          1066




          1066

























              0














              Looks like there is no 'devc_trandate' parameter in the request. So when creating datatime instance its getting None giving you that error.



              Also to create datatime object you need at least 3 parameter for year, month and day. Don't think you can pass string representation of datetime to create an object. You may want to use strptime() method to parse string into datetime object.






              share|improve this answer




























                0














                Looks like there is no 'devc_trandate' parameter in the request. So when creating datatime instance its getting None giving you that error.



                Also to create datatime object you need at least 3 parameter for year, month and day. Don't think you can pass string representation of datetime to create an object. You may want to use strptime() method to parse string into datetime object.






                share|improve this answer


























                  0












                  0








                  0







                  Looks like there is no 'devc_trandate' parameter in the request. So when creating datatime instance its getting None giving you that error.



                  Also to create datatime object you need at least 3 parameter for year, month and day. Don't think you can pass string representation of datetime to create an object. You may want to use strptime() method to parse string into datetime object.






                  share|improve this answer













                  Looks like there is no 'devc_trandate' parameter in the request. So when creating datatime instance its getting None giving you that error.



                  Also to create datatime object you need at least 3 parameter for year, month and day. Don't think you can pass string representation of datetime to create an object. You may want to use strptime() method to parse string into datetime object.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 13 '18 at 4:29









                  RohanRohan

                  38.7k76571




                  38.7k76571






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53273708%2fdjango-having-problem-when-calculate-differences-between-todays-date-and-date%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Full-time equivalent

                      Bicuculline

                      さくらももこ