check if matching query does not exist return empty string
when i try to check if an object exist return it in excel file filed
if not return it an empty 'string'
but i have error in the if
sentence
pkg = Package.objects.get(pk=pk)
price_date_all = PackagePricesAndDates.objects.filter(package=pkg)
if price_date_all.get(territory=ter.pk).sales:
list.append(str(price_date_all.get(territory=ter.pk).sales))
else :
list.append('')
python django django-queryset
add a comment |
when i try to check if an object exist return it in excel file filed
if not return it an empty 'string'
but i have error in the if
sentence
pkg = Package.objects.get(pk=pk)
price_date_all = PackagePricesAndDates.objects.filter(package=pkg)
if price_date_all.get(territory=ter.pk).sales:
list.append(str(price_date_all.get(territory=ter.pk).sales))
else :
list.append('')
python django django-queryset
What does the error say?
– Austin
Nov 25 '18 at 1:43
Please format your code and also add the error stack you got.
– Chiheb Nexus
Nov 25 '18 at 1:43
@Austin PackagePricesAndDates matching query does not exist. when the program loop to find sales for territory it says that does not exist
– Abdeljalil Ouzzine
Nov 25 '18 at 1:45
@Austin if does not exit, i want to return an empty string ''
– Abdeljalil Ouzzine
Nov 25 '18 at 1:53
add a comment |
when i try to check if an object exist return it in excel file filed
if not return it an empty 'string'
but i have error in the if
sentence
pkg = Package.objects.get(pk=pk)
price_date_all = PackagePricesAndDates.objects.filter(package=pkg)
if price_date_all.get(territory=ter.pk).sales:
list.append(str(price_date_all.get(territory=ter.pk).sales))
else :
list.append('')
python django django-queryset
when i try to check if an object exist return it in excel file filed
if not return it an empty 'string'
but i have error in the if
sentence
pkg = Package.objects.get(pk=pk)
price_date_all = PackagePricesAndDates.objects.filter(package=pkg)
if price_date_all.get(territory=ter.pk).sales:
list.append(str(price_date_all.get(territory=ter.pk).sales))
else :
list.append('')
python django django-queryset
python django django-queryset
edited Nov 25 '18 at 1:50
Abdeljalil Ouzzine
asked Nov 25 '18 at 1:41
Abdeljalil OuzzineAbdeljalil Ouzzine
105
105
What does the error say?
– Austin
Nov 25 '18 at 1:43
Please format your code and also add the error stack you got.
– Chiheb Nexus
Nov 25 '18 at 1:43
@Austin PackagePricesAndDates matching query does not exist. when the program loop to find sales for territory it says that does not exist
– Abdeljalil Ouzzine
Nov 25 '18 at 1:45
@Austin if does not exit, i want to return an empty string ''
– Abdeljalil Ouzzine
Nov 25 '18 at 1:53
add a comment |
What does the error say?
– Austin
Nov 25 '18 at 1:43
Please format your code and also add the error stack you got.
– Chiheb Nexus
Nov 25 '18 at 1:43
@Austin PackagePricesAndDates matching query does not exist. when the program loop to find sales for territory it says that does not exist
– Abdeljalil Ouzzine
Nov 25 '18 at 1:45
@Austin if does not exit, i want to return an empty string ''
– Abdeljalil Ouzzine
Nov 25 '18 at 1:53
What does the error say?
– Austin
Nov 25 '18 at 1:43
What does the error say?
– Austin
Nov 25 '18 at 1:43
Please format your code and also add the error stack you got.
– Chiheb Nexus
Nov 25 '18 at 1:43
Please format your code and also add the error stack you got.
– Chiheb Nexus
Nov 25 '18 at 1:43
@Austin PackagePricesAndDates matching query does not exist. when the program loop to find sales for territory it says that does not exist
– Abdeljalil Ouzzine
Nov 25 '18 at 1:45
@Austin PackagePricesAndDates matching query does not exist. when the program loop to find sales for territory it says that does not exist
– Abdeljalil Ouzzine
Nov 25 '18 at 1:45
@Austin if does not exit, i want to return an empty string ''
– Abdeljalil Ouzzine
Nov 25 '18 at 1:53
@Austin if does not exit, i want to return an empty string ''
– Abdeljalil Ouzzine
Nov 25 '18 at 1:53
add a comment |
1 Answer
1
active
oldest
votes
when you use get
on a queryset, it will return either the record or raise a DoesNotExist
exception.
try:
list.append(str(price_date_all.get(territory=ter.pk).sales))
except DoesNotExist:
list.append('')
FWIW, you should rename the list
variable, because its already bound to the list
builtin method for creating lists. Don't reuse names that already exist
Unresolved reference 'DoesNotExist'
– Abdeljalil Ouzzine
Nov 25 '18 at 14:07
yes, because you need to import it :-)
– Jason
Nov 25 '18 at 14:19
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%2f53463970%2fcheck-if-matching-query-does-not-exist-return-empty-string%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
when you use get
on a queryset, it will return either the record or raise a DoesNotExist
exception.
try:
list.append(str(price_date_all.get(territory=ter.pk).sales))
except DoesNotExist:
list.append('')
FWIW, you should rename the list
variable, because its already bound to the list
builtin method for creating lists. Don't reuse names that already exist
Unresolved reference 'DoesNotExist'
– Abdeljalil Ouzzine
Nov 25 '18 at 14:07
yes, because you need to import it :-)
– Jason
Nov 25 '18 at 14:19
add a comment |
when you use get
on a queryset, it will return either the record or raise a DoesNotExist
exception.
try:
list.append(str(price_date_all.get(territory=ter.pk).sales))
except DoesNotExist:
list.append('')
FWIW, you should rename the list
variable, because its already bound to the list
builtin method for creating lists. Don't reuse names that already exist
Unresolved reference 'DoesNotExist'
– Abdeljalil Ouzzine
Nov 25 '18 at 14:07
yes, because you need to import it :-)
– Jason
Nov 25 '18 at 14:19
add a comment |
when you use get
on a queryset, it will return either the record or raise a DoesNotExist
exception.
try:
list.append(str(price_date_all.get(territory=ter.pk).sales))
except DoesNotExist:
list.append('')
FWIW, you should rename the list
variable, because its already bound to the list
builtin method for creating lists. Don't reuse names that already exist
when you use get
on a queryset, it will return either the record or raise a DoesNotExist
exception.
try:
list.append(str(price_date_all.get(territory=ter.pk).sales))
except DoesNotExist:
list.append('')
FWIW, you should rename the list
variable, because its already bound to the list
builtin method for creating lists. Don't reuse names that already exist
answered Nov 25 '18 at 1:56
JasonJason
6,2951770150
6,2951770150
Unresolved reference 'DoesNotExist'
– Abdeljalil Ouzzine
Nov 25 '18 at 14:07
yes, because you need to import it :-)
– Jason
Nov 25 '18 at 14:19
add a comment |
Unresolved reference 'DoesNotExist'
– Abdeljalil Ouzzine
Nov 25 '18 at 14:07
yes, because you need to import it :-)
– Jason
Nov 25 '18 at 14:19
Unresolved reference 'DoesNotExist'
– Abdeljalil Ouzzine
Nov 25 '18 at 14:07
Unresolved reference 'DoesNotExist'
– Abdeljalil Ouzzine
Nov 25 '18 at 14:07
yes, because you need to import it :-)
– Jason
Nov 25 '18 at 14:19
yes, because you need to import it :-)
– Jason
Nov 25 '18 at 14:19
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%2f53463970%2fcheck-if-matching-query-does-not-exist-return-empty-string%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
What does the error say?
– Austin
Nov 25 '18 at 1:43
Please format your code and also add the error stack you got.
– Chiheb Nexus
Nov 25 '18 at 1:43
@Austin PackagePricesAndDates matching query does not exist. when the program loop to find sales for territory it says that does not exist
– Abdeljalil Ouzzine
Nov 25 '18 at 1:45
@Austin if does not exit, i want to return an empty string ''
– Abdeljalil Ouzzine
Nov 25 '18 at 1:53