From d8acd479311086f3372ed61688a7468356198a04 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Tue, 10 Feb 2009 19:00:42 +0100 Subject: [PATCH] Add constants for model field choices. --- influences/models.py | 31 ++++++++++++++++++++----------- influences/views.py | 4 ++-- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/influences/models.py b/influences/models.py index 089e2a3..4c14f7c 100644 --- a/influences/models.py +++ b/influences/models.py @@ -9,19 +9,24 @@ from string import strip # Create your models here. class Character(models.Model): + NEW = 'N' + APPROVED = 'A' STATUS_CHOICES = ( - ('N', _('New')), - ('A', _('Approved')), + (NEW, _('New')), + (APPROVED, _('Approved')), ) + PLAYER = 'P' + NPC = 'N' + CONTACT = 'C' TYPE_CHOICES = ( - ('P', _('Player')), - ('N', _('NPC')), - ('C', _('Contact')), + (PLAYER, _('Player')), + (NPC, _('NPC')), + (CONTACT, _('Contact')), ) created = models.DateField(auto_now_add=1, verbose_name = _("Creation time")) modified = models.DateField(auto_now=1, verbose_name = _("Modification time")) name = models.CharField(max_length=255, verbose_name = _("Name")) - status = models.CharField(max_length=2, choices=STATUS_CHOICES, default='N', verbose_name = _("Status")) + status = models.CharField(max_length=2, choices=STATUS_CHOICES, default=NEW, verbose_name = _("Status")) player = models.ForeignKey(User, verbose_name = _("Player")) contacts = models.ManyToManyField('self', blank = True) type = models.CharField(max_length=2, choices=TYPE_CHOICES, verbose_name=_("Type")) @@ -37,11 +42,15 @@ class Character(models.Model): verbose_name_plural = _("Characters") class Influence(models.Model): + NEW = 'N' + DISCUSSING = 'U' + PROCESSING = 'P' + DONE = 'D' STATUS_CHOICES = ( - ('N', _('New')), - ('U', _('Under discussion')), - ('P', _('Processing')), - ('D', _('Done')), + (NEW, _('New')), + (DISCUSSING, _('Under discussion')), + (PROCESSING, _('Processing')), + (DONE, _('Done')), ) created = models.DateField(auto_now_add=1, verbose_name = _("Creation time")) modified = models.DateField(auto_now=1, verbose_name = _("Modification time")) @@ -52,7 +61,7 @@ class Influence(models.Model): summary = models.CharField(max_length=255, verbose_name = _("Summary")) description = models.TextField(verbose_name = _("Description")) todo = models.TextField(blank=True, verbose_name = _("Todo")) - status = models.CharField(max_length=1, choices=STATUS_CHOICES, default='N', verbose_name = _("Status")) + status = models.CharField(max_length=1, choices=STATUS_CHOICES, default=NEW, verbose_name = _("Status")) longterm = models.BooleanField(default=False, verbose_name = _("Long term")) result = models.TextField(blank=True,verbose_name = _("Result")) diff --git a/influences/views.py b/influences/views.py index 334bfc7..8b2961b 100644 --- a/influences/views.py +++ b/influences/views.py @@ -20,9 +20,9 @@ from xerxes.tools.misc import make_choices def add_influence(request, character_id=None): initial = {} # Get the current user's characters - my_chars = request.user.character_set.all().filter(type__in=['P', 'N']) + my_chars = request.user.character_set.all().filter(type__in=[Character.PLAYER, Character.NPC]) # Get all chars - all_chars = Character.objects.all().filter(type__in=['P', 'N']) + all_chars = Character.objects.all().filter(type__in=[Character.PLAYER, Character.NPC]) # If a character_id was specified in the url, or there is only one # character, preselect it. -- 2.30.2