Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 March 26, 2008 16:57:33

j.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Need advice on design of models


I'm creating an election site and I have created the following 4 main
classes:

class Election(models.Model):
election_name = models.CharField(max_length=100, unique=True)
slug = models.SlugField(prepopulate_from=("election_name",),
unique=True)
election_date = models.DateField()

class Precinct(models.Model):
precinct_number = models.CharField(max_length=4, blank=True)
precinct_name = models.CharField(max_length=100)
slug =
models.SlugField(prepopulate_from=("precinct_number","precinct_name"),
unique=True)
location = models.CharField(max_length=100)
address = models.CharField(max_length=100)

class Candidate(models.Model):
first_name = models.CharField(max_length=50)
middle_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
display_name = models.CharField(max_length=75)
slug = models.SlugField(prepopulate_from=("display_name",),
unique=True)

class Office(models.Model):
office_name = models.CharField(max_length=100, unique=True)
slug = models.SlugField(prepopulate_from=("office_name",),)

Since my mind is still functioning like a DBA, I'm unsure as to what
kind of classes to create for the following:

Election <-> Precinct
This is many to many but an additional field needs to be included
(total_persons_voting). I guess this would be a separate class
because of this extra field?

Election <-> Precinct <-> Office
I believe this would be a many to many relationship between (Election,
Precinct) and Office since in any election, different precincts may
contain different offices.

Election <-> Precinct <-> Office <-> Candidate
Once again, this would be a many to many relationship between
(Election, Precinct, Office) and Candidate with an additional field
for total_votes

Or would it be simpler (or correct) to create the following class:
class Results(models.Model):
election = models.ForeignKey(election)
precinct = models.ForeignKey(precinct)
office = models.ForeignKey(office)
candidate = models.ForeignKey(candidate)
total_votes = models.PositiveIntegerField()
--~--~---------~--~----~------------~-------~--~----~
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
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en-~----------~----~----~----~------~----~------~--~---

Offline

Board footer

Moderator control

Enjoy the 16th of December
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support