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.

On Tue, Jan 6, 2015 at 2:20 PM, <jobopps...@gmail.com> wrote:

> 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:
>
> https://snipt.net/joboppsgpp/code-with-bug-d8fa565f
>
> 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.
>
>  --
> 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+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@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
> <https://groups.google.com/d/msgid/django-users/b8fa1696-4a29-4dcf-b9af-08b704790ae8%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@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/CALn3ei315dpd8wxWFPy0%2Bt_Ru223CNJzhmFX6BZE5ENSE8%2BWnw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to