Last active
December 30, 2015 05:48
-
-
Save evdb/7784603 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
from autoslug import AutoSlugField | |
from pombola.core.models import Person | |
# TODO | |
# | |
# - add a source for the data, possibly as a field on the Release? | |
# - resolve how to differentiate between items that are one-offs (like gift to person) and ongoing (like employment or land ownership). Concern is that one-offs may get lost if only the latest release is shown, or duplicated if they are included in several releases. | |
class Category(models.Model): | |
name = models.CharField(max_length=300, unique=True) | |
slug = AutoSlugField(unique=True, populate_from='name') | |
sort_order = models.IntegerField() | |
def __unicode__(self): | |
return self.name | |
class Meta(object): | |
ordering = ('sort_order', 'name') | |
verbose_name_plural = 'categories' | |
class Release(models.Model): | |
name = models.CharField(max_length=300, unique=True) | |
slug = AutoSlugField(unique=True, populate_from='name') | |
date = models.DateField() | |
def __unicode__(self): | |
return self.name | |
class Meta(object): | |
ordering = ('date', 'name') | |
class Entry(models.Model): | |
person = models.ForeignKey(Person, related_name="interests_register_entries") | |
category = models.ForeignKey(Category, related_name="entries") | |
release = models.ForeignKey(Release, related_name="entries") | |
sort_order = models.IntegerField() | |
def __unicode__(self): | |
return u'Entry for {} in {} ({})'.format(self.person, self.category, self.release) | |
class Meta(object): | |
ordering = ('person__legal_name', '-release__date', 'category__sort_order', 'category__name', 'sort_order') | |
verbose_name_plural = 'entries' | |
class EntryLineItem(models.Model): | |
entry = models.ForeignKey(Entry, related_name="line_items") | |
key = models.CharField(max_length=240) | |
value = models.TextField() | |
def __unicode__(self): | |
return u"{}: {}".format(self.key, self.value) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(pombola-virtualenv)evdb@custard ~/mysociety/pombola_root/pombola $ ./manage.py test interests_register | |
Running in test mode! (testing root_dir is '/Users/evdb/mysociety/pombola_root/testing') | |
Creating test database for alias 'default'... | |
/Users/evdb/mysociety/pombola_root/pombola-virtualenv/lib/python2.7/site-packages/autoslug/utils.py:30: RuntimeWarning: Argument <type 'str'> is not an unicode object. Passing an encoded string will likely have unexpected results. | |
return django_slugify(unidecode(value)) | |
.. | |
---------------------------------------------------------------------- | |
Ran 2 tests in 0.038s | |
OK | |
Destroying test database for alias 'default'... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment