Matching logic is case sensitive when I want it case insensitive

21 views
Skip to first unread message

jobop...@gmail.com

unread,
Jan 6, 2015, 12:20:12 PM1/6/15
to django...@googlegroups.com
Hi,

I have a bug where when I upload data from a csv into my database into a model that houses social accounts (eg a twitter value, a facebook value etc) it is adding new social account objects if there's a discrepency between the casing of the value in the csv and the value that is already in the db.  I don't want to add a new object if a case insensitive version of the value is already represented in the db.  So if "JoeSchmoe" is in the csv, and an object with a value of "joeschmore" is in the db already, I don't want to create a new social account object, I want it to behave the same way it currently behaves for case sensitive matches.  

I think I have found where in the code the problem is:


However, I don't program myself, and since this seems like a trivial change, I was hoping someone here could suggest a fix for my issue.

Thanks in advance.

Vijay Khemlani

unread,
Jan 6, 2015, 1:08:14 PM1/6/15
to django...@googlegroups.com
on line 12 you would need a more complex logic

try:
    obj = SocialAccount.objects.get(social_profile=profile, service=service, value__iexact=value)
except SocialAccount.DoesNotExist:
    obj = SocialAccount.objects.create(social_profile=profile, service=service, value=value)

(assuming "value" is the case insensitive field)

A little more permanent solution would be to always store the value in lowercase and make all the queries using lowercase values, as the solution above only prevents the bug in this method.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b8fa1696-4a29-4dcf-b9af-08b704790ae8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

jobop...@gmail.com

unread,
Jan 6, 2015, 1:58:04 PM1/6/15
to django...@googlegroups.com
This worked beautifully. Thanks Vijay!

(ps thanks for the suggestions regarding a long-term solution).
Reply all
Reply to author
Forward
0 new messages