It is probably better to use candidates.count(), rather than
len(candidates). len will cause the whole queryset to be loaded into
memory. It doesn't look like you use it later, so that is kind of a
waste.
Hope that helps,
Alex
>From django docs:
Note: Don't use len() on QuerySets if all you want
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 wrote:
> Thanks Dan, I'll give it a shot
>
> On Jun 8, 6:00 pm, Dan Harris wrote:
>
> > Pe
Thanks Dan, I'll give it a shot
On Jun 8, 6:00 pm, Dan Harris 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 = mode
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.CharFie
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 wit
5 matches
Mail list logo