Get Queryset by removing White spaces in the middle of the string - Django [duplicate]












0
















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.










share|improve this question













marked as duplicate by ruddra, bruno desthuilliers django
Users with the  django badge can single-handedly close django questions as duplicates and reopen them as needed.

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
















0
















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.










share|improve this question













marked as duplicate by ruddra, bruno desthuilliers django
Users with the  django badge can single-handedly close django questions as duplicates and reopen them as needed.

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














0












0








0









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.










share|improve this question















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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 3 at 12:34









MOHAMED AZARUDEENMOHAMED AZARUDEEN

43




43




marked as duplicate by ruddra, bruno desthuilliers django
Users with the  django badge can single-handedly close django questions as duplicates and reopen them as needed.

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 django
Users with the  django badge can single-handedly close django questions as duplicates and reopen them as needed.

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



















  • 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












1 Answer
1






active

oldest

votes


















1














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(" "," "))





share|improve this answer
























  • 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


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














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(" "," "))





share|improve this answer
























  • 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
















1














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(" "," "))





share|improve this answer
























  • 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














1












1








1







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(" "," "))





share|improve this answer













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(" "," "))






share|improve this answer












share|improve this answer



share|improve this answer










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



















  • 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





Popular posts from this blog

Mossoró

Error while reading .h5 file using the rhdf5 package in R

Pushsharp Apns notification error: 'InvalidToken'