Get Queryset by removing White spaces in the middle of the string - Django [duplicate]
This question already has an answer here:
django: how to filter model field values with out space?
3 answers
I am having table which has column "name". I want to get record by providing name, which contains extra white spaces in middle.
my table looks like as follows.
id name
1 Raj Kumar
2 Praveen Kumar
3 Sandya
My Table contain records in which row contain only one spaces at the middle. I want to make a query as follows.
input_name = 'Raj Kumar'(Which contain two spaces)
a = A.objects.get(name=input_name)
The above will return "None". Kindly help me out to solve the problem.
python django
marked as duplicate by ruddra, bruno desthuilliers
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 3 at 13:23
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
django: how to filter model field values with out space?
3 answers
I am having table which has column "name". I want to get record by providing name, which contains extra white spaces in middle.
my table looks like as follows.
id name
1 Raj Kumar
2 Praveen Kumar
3 Sandya
My Table contain records in which row contain only one spaces at the middle. I want to make a query as follows.
input_name = 'Raj Kumar'(Which contain two spaces)
a = A.objects.get(name=input_name)
The above will return "None". Kindly help me out to solve the problem.
python django
marked as duplicate by ruddra, bruno desthuilliers
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 3 at 13:23
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
see the duplicate - and specially the second part or Daniel Roseman's answer - for the correct solution (which is to store a normalized version of 'name' along the submitted one and use the same normalization on the input).
– bruno desthuilliers
Jan 3 at 13:25
add a comment |
This question already has an answer here:
django: how to filter model field values with out space?
3 answers
I am having table which has column "name". I want to get record by providing name, which contains extra white spaces in middle.
my table looks like as follows.
id name
1 Raj Kumar
2 Praveen Kumar
3 Sandya
My Table contain records in which row contain only one spaces at the middle. I want to make a query as follows.
input_name = 'Raj Kumar'(Which contain two spaces)
a = A.objects.get(name=input_name)
The above will return "None". Kindly help me out to solve the problem.
python django
This question already has an answer here:
django: how to filter model field values with out space?
3 answers
I am having table which has column "name". I want to get record by providing name, which contains extra white spaces in middle.
my table looks like as follows.
id name
1 Raj Kumar
2 Praveen Kumar
3 Sandya
My Table contain records in which row contain only one spaces at the middle. I want to make a query as follows.
input_name = 'Raj Kumar'(Which contain two spaces)
a = A.objects.get(name=input_name)
The above will return "None". Kindly help me out to solve the problem.
This question already has an answer here:
django: how to filter model field values with out space?
3 answers
python django
python django
asked Jan 3 at 12:34
MOHAMED AZARUDEENMOHAMED AZARUDEEN
43
43
marked as duplicate by ruddra, bruno desthuilliers
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 3 at 13:23
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by ruddra, bruno desthuilliers
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 3 at 13:23
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
see the duplicate - and specially the second part or Daniel Roseman's answer - for the correct solution (which is to store a normalized version of 'name' along the submitted one and use the same normalization on the input).
– bruno desthuilliers
Jan 3 at 13:25
add a comment |
see the duplicate - and specially the second part or Daniel Roseman's answer - for the correct solution (which is to store a normalized version of 'name' along the submitted one and use the same normalization on the input).
– bruno desthuilliers
Jan 3 at 13:25
see the duplicate - and specially the second part or Daniel Roseman's answer - for the correct solution (which is to store a normalized version of 'name' along the submitted one and use the same normalization on the input).
– bruno desthuilliers
Jan 3 at 13:25
see the duplicate - and specially the second part or Daniel Roseman's answer - for the correct solution (which is to store a normalized version of 'name' along the submitted one and use the same normalization on the input).
– bruno desthuilliers
Jan 3 at 13:25
add a comment |
1 Answer
1
active
oldest
votes
if the there is only one condition(two spaces in between) then you can just replace two spaces with one space like below
input_name = 'Raj Kumar'(Which contain two spaces)
a = A.objects.get(name=input_name.replace(" "," "))
Namaware has posted a perfect solution for all cases where there are more then a single space between the words
– Shubham Paliwal
Jan 3 at 12:46
@ShubhamPaliwal Namaware solution is far from perfect actually - what if it's the db values that contains duplicated spaces ?
– bruno desthuilliers
Jan 3 at 13:19
Though the answer provided by @Daniel Roseman is worth referencing but Mohamed specifically specified that the error he is encountering is at the time of user input.
– Shubham Paliwal
Jan 3 at 15:02
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
if the there is only one condition(two spaces in between) then you can just replace two spaces with one space like below
input_name = 'Raj Kumar'(Which contain two spaces)
a = A.objects.get(name=input_name.replace(" "," "))
Namaware has posted a perfect solution for all cases where there are more then a single space between the words
– Shubham Paliwal
Jan 3 at 12:46
@ShubhamPaliwal Namaware solution is far from perfect actually - what if it's the db values that contains duplicated spaces ?
– bruno desthuilliers
Jan 3 at 13:19
Though the answer provided by @Daniel Roseman is worth referencing but Mohamed specifically specified that the error he is encountering is at the time of user input.
– Shubham Paliwal
Jan 3 at 15:02
add a comment |
if the there is only one condition(two spaces in between) then you can just replace two spaces with one space like below
input_name = 'Raj Kumar'(Which contain two spaces)
a = A.objects.get(name=input_name.replace(" "," "))
Namaware has posted a perfect solution for all cases where there are more then a single space between the words
– Shubham Paliwal
Jan 3 at 12:46
@ShubhamPaliwal Namaware solution is far from perfect actually - what if it's the db values that contains duplicated spaces ?
– bruno desthuilliers
Jan 3 at 13:19
Though the answer provided by @Daniel Roseman is worth referencing but Mohamed specifically specified that the error he is encountering is at the time of user input.
– Shubham Paliwal
Jan 3 at 15:02
add a comment |
if the there is only one condition(two spaces in between) then you can just replace two spaces with one space like below
input_name = 'Raj Kumar'(Which contain two spaces)
a = A.objects.get(name=input_name.replace(" "," "))
if the there is only one condition(two spaces in between) then you can just replace two spaces with one space like below
input_name = 'Raj Kumar'(Which contain two spaces)
a = A.objects.get(name=input_name.replace(" "," "))
answered Jan 3 at 12:39
Amit NanawareAmit Nanaware
1,1881114
1,1881114
Namaware has posted a perfect solution for all cases where there are more then a single space between the words
– Shubham Paliwal
Jan 3 at 12:46
@ShubhamPaliwal Namaware solution is far from perfect actually - what if it's the db values that contains duplicated spaces ?
– bruno desthuilliers
Jan 3 at 13:19
Though the answer provided by @Daniel Roseman is worth referencing but Mohamed specifically specified that the error he is encountering is at the time of user input.
– Shubham Paliwal
Jan 3 at 15:02
add a comment |
Namaware has posted a perfect solution for all cases where there are more then a single space between the words
– Shubham Paliwal
Jan 3 at 12:46
@ShubhamPaliwal Namaware solution is far from perfect actually - what if it's the db values that contains duplicated spaces ?
– bruno desthuilliers
Jan 3 at 13:19
Though the answer provided by @Daniel Roseman is worth referencing but Mohamed specifically specified that the error he is encountering is at the time of user input.
– Shubham Paliwal
Jan 3 at 15:02
Namaware has posted a perfect solution for all cases where there are more then a single space between the words
– Shubham Paliwal
Jan 3 at 12:46
Namaware has posted a perfect solution for all cases where there are more then a single space between the words
– Shubham Paliwal
Jan 3 at 12:46
@ShubhamPaliwal Namaware solution is far from perfect actually - what if it's the db values that contains duplicated spaces ?
– bruno desthuilliers
Jan 3 at 13:19
@ShubhamPaliwal Namaware solution is far from perfect actually - what if it's the db values that contains duplicated spaces ?
– bruno desthuilliers
Jan 3 at 13:19
Though the answer provided by @Daniel Roseman is worth referencing but Mohamed specifically specified that the error he is encountering is at the time of user input.
– Shubham Paliwal
Jan 3 at 15:02
Though the answer provided by @Daniel Roseman is worth referencing but Mohamed specifically specified that the error he is encountering is at the time of user input.
– Shubham Paliwal
Jan 3 at 15:02
add a comment |
see the duplicate - and specially the second part or Daniel Roseman's answer - for the correct solution (which is to store a normalized version of 'name' along the submitted one and use the same normalization on the input).
– bruno desthuilliers
Jan 3 at 13:25