If you already have a unique key on the project's name field, then you're good to go--no duplicates will ever get inserted. No need to do any filtering ahead of time--just put each save() in a try/except block that catches the error you get and does nothing.
-Jeff On Nov 25, 4:53 pm, "Alex Jillard" <[EMAIL PROTECTED]> wrote: > Thanks for the replies Jeff and Rajesh. I'll look int both of those options > and see what I can come up with. My model is set to have the name of the > project to be unique, so it was throwing an error if a duplicate was added. > > Jeff, unfortunatly the initial list of CVS projects is just a string that > I'm splitting, so I can't do it as I build that list. > > Thanks again > > On Tue, Nov 25, 2008 at 4:38 PM, Rajesh Dhawan <[EMAIL PROTECTED]>wrote: > > > > > Hi Alex, > > > > Here is the code that I use. Output_list is from CVS and > > current_projects > > > is from the database. Is there a faster way to do this, or a built in > > > method in Python? This code works fine now, but I can see it getting > > slow. > > > > for b in output_list: > > > found = False > > > for i in current_projects: > > > if i.name == b: > > > found = True > > > if not found: > > > new_projects.append(b) > > > Try converting the two project name lists into Python sets and take a > > difference: > > > full_list = set(output_list) > > db_list = set([i.name for i in current_projects]) > > new_projects = full_list - db_list > > > You should also add a unique=True attribute to your project.name > > field. > > > -Rajesh D > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---