Just to let you know, this code worked out nicely. I made a few changes to the bottom save function:
if len(candidates) > 1: raise Exception candidates.update(incumbent=True) On Jun 8, 6:11 pm, Nick <nickt...@gmail.com> wrote: > Thanks Dan, I'll give it a shot > > On Jun 8, 6:00 pm, Dan Harris <dih0...@gmail.com> wrote: > > > Perhaps not the greatest way of doing things, but simple to code/read: > > > class Candidate(models.Model): > > first_name = models.CharField(max_length=30) > > last_name = models.CharField(max_length=30) > > incumbent = models.BooleanField() > > > class HoldsOffice(models.Model): > > first_name = models.CharField(max_length=30) > > last_name = models.CharField(max_length=30) > > > for officer in HoldsOffice.objects.all(): > > candidates = > > Candidate.objects.filter(first_name__iequals=officer.first_name).filter(last_name__iequals=officer.last_name) > > > if len(candidates)>0: > > raise Exception("More than 1 match found") > > candidates[0].incumbent = True > > candidates[0].save() > > > Something like that might work for you assuming that the models and > > stuff are similar. Also, this code is just off the top of my head, so > > who knows if it will actually work :) > > > Cheers, > > > Dan Harris > > dih0...@gmail.com > > > On Jun 8, 6:30 pm, Nick <nickt...@gmail.com> wrote: > > > > I have two models. One is a list of candidates that have filed to run > > > for office. The second is a list of people who currently hold > > > office. > > > > I'd like to compare the two tables and whenever a match is found > > > between the two (an entry in the candidate table shares the same > > > last_name and first_name with an office holder from the holds office > > > table) I'd like to check off a box in the Candidate table called > > > 'incumbent'. > > > > how would I begin to do this. They both have columns called last_name > > > and first_name that I can use to compare but I don't know the syntax. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.