diff options
| author | Adrian Holovaty <adrian@holovaty.com> | 2005-08-25 22:51:30 +0000 |
|---|---|---|
| committer | Adrian Holovaty <adrian@holovaty.com> | 2005-08-25 22:51:30 +0000 |
| commit | 25264c86048d442a4885dfebae94510e2fa0c1e4 (patch) | |
| tree | bb02799b624fb0d6f931d208509ffbb50d00e358 /django/models/core.py | |
| parent | aec0a73d73324820c767758afd250fc21a2896ef (diff) | |
Fixed #122 -- BIG, BACKWARDS-INCOMPATIBLE CHANGE. Changed model syntax to use fieldname=FieldClass() syntax. See ModelSyntaxChangeInstructions for important information on how to change your models
git-svn-id: http://code.djangoproject.com/svn/django/trunk@549 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/models/core.py')
| -rw-r--r-- | django/models/core.py | 132 |
1 files changed, 62 insertions, 70 deletions
diff --git a/django/models/core.py b/django/models/core.py index e94a35b694..939373f7ec 100644 --- a/django/models/core.py +++ b/django/models/core.py @@ -1,12 +1,11 @@ from django.core import meta, validators class Site(meta.Model): - db_table = 'sites' - fields = ( - meta.CharField('domain', 'domain name', maxlength=100), - meta.CharField('name', 'display name', maxlength=50), - ) - ordering = ('domain',) + domain = meta.CharField('domain name', maxlength=100) + name = meta.CharField('display name', maxlength=50) + class META: + db_table = 'sites' + ordering = ('domain',) def __repr__(self): return self.domain @@ -17,25 +16,23 @@ class Site(meta.Model): return get_object(pk=SITE_ID) class Package(meta.Model): - db_table = 'packages' - fields = ( - meta.CharField('label', maxlength=20, primary_key=True), - meta.CharField('name', maxlength=30, unique=True), - ) - ordering = ('name',) + label = meta.CharField(maxlength=20, primary_key=True) + name = meta.CharField(maxlength=30, unique=True) + class META: + db_table = 'packages' + ordering = ('name',) def __repr__(self): return self.name class ContentType(meta.Model): - db_table = 'content_types' - fields = ( - meta.CharField('name', maxlength=100), - meta.ForeignKey(Package, name='package'), - meta.CharField('python_module_name', maxlength=50), - ) - ordering = ('package', 'name') - unique_together = (('package', 'python_module_name'),) + name = meta.CharField(maxlength=100) + package = meta.ForeignKey(Package, db_column='package') + python_module_name = meta.CharField(maxlength=50) + class META: + db_table = 'content_types' + ordering = ('package', 'name') + unique_together = (('package', 'python_module_name'),) def __repr__(self): return "%s | %s" % (self.package, self.name) @@ -54,49 +51,45 @@ class ContentType(meta.Model): return self.get_model_module().get_object(**kwargs) class Redirect(meta.Model): - db_table = 'redirects' - fields = ( - meta.ForeignKey(Site, radio_admin=meta.VERTICAL), - meta.CharField('old_path', 'redirect from', maxlength=200, db_index=True, - help_text="This should be an absolute path, excluding the domain name. Example: '/events/search/'."), - meta.CharField('new_path', 'redirect to', maxlength=200, blank=True, - help_text="This can be either an absolute path (as above) or a full URL starting with 'http://'."), - ) - unique_together=(('site_id', 'old_path'),) - ordering = ('old_path',) - admin = meta.Admin( - list_display = ('__repr__',), - list_filter = ('site_id',), - search_fields = ('old_path', 'new_path'), - ) + site = meta.ForeignKey(Site, radio_admin=meta.VERTICAL) + old_path = meta.CharField('redirect from', maxlength=200, db_index=True, + help_text="This should be an absolute path, excluding the domain name. Example: '/events/search/'.") + new_path = meta.CharField('redirect to', maxlength=200, blank=True, + help_text="This can be either an absolute path (as above) or a full URL starting with 'http://'.") + class META: + db_table = 'redirects' + unique_together=(('site', 'old_path'),) + ordering = ('old_path',) + admin = meta.Admin( + list_filter = ('site',), + search_fields = ('old_path', 'new_path'), + ) def __repr__(self): return "%s ---> %s" % (self.old_path, self.new_path) class FlatFile(meta.Model): - db_table = 'flatfiles' - verbose_name = 'flat page' - fields = ( - meta.CharField('url', 'URL', maxlength=100, validator_list=[validators.isAlphaNumericURL], - help_text="Example: '/about/contact/'. Make sure to have leading and trailing slashes."), - meta.CharField('title', maxlength=200), - meta.TextField('content', help_text="Full HTML is allowed."), - meta.BooleanField('enable_comments'), - meta.CharField('template_name', maxlength=70, blank=True, - help_text="Example: 'flatfiles/contact_page'. If this isn't provided, the system will use 'flatfiles/default'."), - meta.BooleanField('registration_required', - help_text="If this is checked, only logged-in users will be able to view the page."), - meta.ManyToManyField(Site), - ) - ordering = ('url',) - admin = meta.Admin( - fields = ( - (None, {'fields': ('url', 'title', 'content', 'sites')}), - ('Advanced options', {'classes': 'collapse', 'fields': ('enable_comments', 'registration_required', 'template_name')}), - ), - list_filter = ('sites',), - search_fields = ('url', 'title'), - ) + url = meta.CharField('URL', maxlength=100, validator_list=[validators.isAlphaNumericURL], + help_text="Example: '/about/contact/'. Make sure to have leading and trailing slashes.") + title = meta.CharField(maxlength=200) + content = meta.TextField() + enable_comments = meta.BooleanField() + template_name = meta.CharField(maxlength=70, blank=True, + help_text="Example: 'flatfiles/contact_page'. If this isn't provided, the system will use 'flatfiles/default'.") + registration_required = meta.BooleanField(help_text="If this is checked, only logged-in users will be able to view the page.") + sites = meta.ManyToManyField(Site) + class META: + db_table = 'flatfiles' + verbose_name = 'flat page' + ordering = ('url',) + admin = meta.Admin( + fields = ( + (None, {'fields': ('url', 'title', 'content', 'sites')}), + ('Advanced options', {'classes': 'collapse', 'fields': ('enable_comments', 'registration_required', 'template_name')}), + ), + list_filter = ('sites',), + search_fields = ('url', 'title'), + ) def __repr__(self): return "%s -- %s" % (self.url, self.title) @@ -108,18 +101,17 @@ import base64, md5, random, sys import cPickle as pickle class Session(meta.Model): - fields = ( - meta.CharField('session_key', maxlength=40, primary_key=True), - meta.TextField('session_data'), - meta.DateTimeField('expire_date'), - ) - module_constants = { - 'base64': base64, - 'md5': md5, - 'pickle': pickle, - 'random': random, - 'sys': sys, - } + session_key = meta.CharField(maxlength=40, primary_key=True) + session_data = meta.TextField() + expire_date = meta.DateTimeField() + class META: + module_constants = { + 'base64': base64, + 'md5': md5, + 'pickle': pickle, + 'random': random, + 'sys': sys, + } def get_decoded(self): from django.conf.settings import SECRET_KEY |
