Django: Having problem when calculate differences between today's date and date in database
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
add a comment |
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
can you please share your full traceback?
– ruddra
Nov 13 '18 at 4:26
add a comment |
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
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
django
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
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.
add a comment |
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.
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 14 '18 at 1:34
YvKlYvKl
1066
1066
add a comment |
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 13 '18 at 4:29
RohanRohan
38.7k76571
38.7k76571
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
can you please share your full traceback?
– ruddra
Nov 13 '18 at 4:26