On 02-Oct-07, at 2:46 PM, Nis Jørgensen wrote:
>> improper formatting - but am unable to find out where exactly the >> formatting is improper. If I put this function in the 'save' method >> of the model - I get the same error. > > This is an instance of the problem described here: > > http://code.djangoproject.com/ticket/5043 yes - looks like it. Anyway, until that is resolved I did a work around. In my model 'word' is unique. So the behaviour expected is, if 'word' is already in the table, do not insert. If it is not there, insert. I found that django is using get_or_create, and when it finds a record where 'word' equals the 'word' I am trying to insert *and* one or more of the other fields differ from the existing record, it tries to insert and bumps into duplicate key error. I now do get_or_create, *only* using the value of 'word' in the query - if created, then I do an update to set the other fields - otherwise I leave it alone. So my save method is like this now: def save(self): """dumping all the words in the word database""" super(Lesson_line,self).save() spkwords = self.sentencespk.split() for wrd in spkwords: lng=self.lesson.language wd = wrd.strip('!.,?') a,w = Word.objects.get_or_create(word=wd,language=lng) if w: a.written=False a.save() wrtwords = self.sentencewrt.split() for wrd in wrtwords: lng=self.lesson.language wd = wrd.strip('!.,?') a,w = Word.objects.get_or_create(word=wd,language=lng) if w: a.written=True a.save() -- regards kg http://lawgon.livejournal.com http://nrcfosshelpline.in/web/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---