Permalink
Browse files

SchemaField admin: limit choices of real_name to valid values

  • Loading branch information...
1 parent c0a594d commit 1fa4fecf0befa7297033af0f2b6344a86b101046 @slinkp slinkp committed Jun 13, 2011
Showing with 11 additions and 0 deletions.
  1. +11 −0 ebpub/ebpub/db/models.py
@@ -24,6 +24,7 @@
from ebpub.streets.models import Block
from ebpub.utils.text import slugify
+import re
import datetime
# Need these monkeypatches for "natural key" support during fixture load/dump.
@@ -34,6 +35,15 @@
FREQUENCY_CHOICES = [(a, a) for a in FREQUENCY_CHOICES]
+def get_valid_real_names():
+ """
+ Field names of ``Attribute``, suitable for use as
+ ``SchemaField.real_name``.
+ """
+ for name in sorted(Attribute._meta.get_all_field_names()):
+ if re.search(r'\d\d$', name):
+ yield name
+
def field_mapping(schema_id_list):
"""
Given a list of schema IDs, returns a dictionary of dictionaries, mapping
@@ -170,6 +180,7 @@ class SchemaField(models.Model):
real_name = models.CharField(
max_length=10,
help_text="Column name in the Attribute model. 'varchar01', 'varchar02', etc.",
+ choices=((name, name) for name in get_valid_real_names()),
)
display = models.BooleanField(
default=True,

0 comments on commit 1fa4fec

Please sign in to comment.