Re: Do I need two classes that are identical because I want to use two database tables?
On Mar 28, 9:34 pm, andy baxter <[EMAIL PROTECTED]> wrote: > Peter Rowell wrote: > >> So should I just create two classes that are identical but name one > >> CurrentElectionResults and the other PastElectionResults? > > Can't you just have a single class 'ElectionResults' and add a field > called 'current'? > > I'm planning on doing something similar with my app. > > andy. I could do that, but I'd like to keep my current election results in its own table since I will be importing data through a CSV file. The CSV file will get updated frequently over the course of about 2 hours. Because of this, I plan to either wipe all data from my results table before importing the CSV file. This is why I want separate tables. One results table would hold all the past election results while the other would get the imports from the CSV file. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Do I need two classes that are identical because I want to use two database tables?
Peter Rowell wrote: >> So should I just create two classes that are identical but name one >> CurrentElectionResults and the other PastElectionResults? >> Can't you just have a single class 'ElectionResults' and add a field called 'current'? I'm planning on doing something similar with my app. andy. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Do I need two classes that are identical because I want to use two database tables?
> So should I just create two classes that are identical but name one > CurrentElectionResults and the other PastElectionResults? That would be one way of doing it. There are promises of subclassable (?) Models in the works, but it hasn't been released yet. If there are a fair number of methods connected with the class, you could avoid duplicating them by creating a third class and then using multiple inheritance for the two models. A project I recently finished had a dozen different types of content objects (articles, q&a, videos, etc.), each with unique aspects to it, but all of which needed functions for determining parent sections, building breadcrumbs, etc. etc., and this technique handled it nicely. E.g. class ElectionResultMethods: """Common methods for the two ElectionResult classes"" def foo(self): pass def bar(self): pass class CurrentElectionResults(models.Model, ElectionResultsMethods): etc. class PassElectionResults(models.Model, ElectionResultsMethods): etc. HTH, Peter --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Do I need two classes that are identical because I want to use two database tables?
I've created a class called ElectionResults that contains the following fields: election = models.ForeignKey(Election) precinct = models.ForeignKey(Precinct) office = models.ForeignKey(Office) candidate = models.ForeignKey(Candidate) total_votes = models.PositiveIntegerField(default=0) Here's the problem. I will need to have a current Results table generated for several reasons. One is performance. Keeping Current Election Results in their own table away from past election results will result in quicker lookups. The other reason is that the current election results table will need to be dropped and recreated on a timely basis. The reason is the data will be imported from a CSV file that gets updated frequently. So should I just create two classes that are identical but name one CurrentElectionResults and the other PastElectionResults? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---