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 | |
| 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')
| -rw-r--r-- | django/models/auth.py | 136 | ||||
| -rw-r--r-- | django/models/core.py | 132 |
2 files changed, 126 insertions, 142 deletions
diff --git a/django/models/auth.py b/django/models/auth.py index 9ab403af34..430cad192a 100644 --- a/django/models/auth.py +++ b/django/models/auth.py @@ -2,65 +2,60 @@ from django.core import meta, validators from django.models import core class Permission(meta.Model): - fields = ( - meta.CharField('name', maxlength=50), - meta.ForeignKey(core.Package, name='package'), - meta.CharField('codename', maxlength=100), - ) - unique_together = (('package', 'codename'),) - ordering = ('package', 'codename') + name = meta.CharField(maxlength=50) + package = meta.ForeignKey(core.Package, db_column='package') + codename = meta.CharField(maxlength=100) + class META: + unique_together = (('package', 'codename'),) + ordering = ('package', 'codename') def __repr__(self): return "%s | %s" % (self.package, self.name) class Group(meta.Model): - fields = ( - meta.CharField('name', maxlength=80, unique=True), - meta.ManyToManyField(Permission, blank=True, filter_interface=meta.HORIZONTAL), - ) - ordering = ('name',) - admin = meta.Admin( - search_fields = ('name',), - ) + name = meta.CharField(maxlength=80, unique=True) + permissions = meta.ManyToManyField(Permission, blank=True, filter_interface=meta.HORIZONTAL) + class META: + ordering = ('name',) + admin = meta.Admin( + search_fields = ('name',), + ) def __repr__(self): return self.name class User(meta.Model): - fields = ( - meta.CharField('username', maxlength=30, unique=True, - validator_list=[validators.isAlphaNumeric]), - meta.CharField('first_name', maxlength=30, blank=True), - meta.CharField('last_name', maxlength=30, blank=True), - meta.EmailField('email', 'e-mail address', blank=True), - meta.CharField('password_md5', 'password', maxlength=32, help_text="Use an MD5 hash -- not the raw password."), - meta.BooleanField('is_staff', 'staff status', - help_text="Designates whether the user can log into this admin site."), - meta.BooleanField('is_active', 'active', default=True), - meta.BooleanField('is_superuser', 'superuser status'), - meta.DateTimeField('last_login', default=meta.LazyDate()), - meta.DateTimeField('date_joined', default=meta.LazyDate()), - meta.ManyToManyField(Group, blank=True, - help_text="In addition to the permissions manually assigned, this user will also get all permissions granted to each group he/she is in."), - meta.ManyToManyField(Permission, name='user_permissions', blank=True, filter_interface=meta.HORIZONTAL), - ) - module_constants = { - 'SESSION_KEY': '_auth_user_id', - } - ordering = ('username',) - exceptions = ('SiteProfileNotAvailable',) - admin = meta.Admin( - fields = ( - (None, {'fields': ('username', 'password_md5')}), - ('Personal info', {'fields': ('first_name', 'last_name', 'email')}), - ('Permissions', {'fields': ('is_staff', 'is_active', 'is_superuser', 'user_permissions')}), - ('Important dates', {'fields': ('last_login', 'date_joined')}), - ('Groups', {'fields': ('groups',)}), - ), - list_display = ('username', 'email', 'first_name', 'last_name', 'is_staff'), - list_filter = ('is_staff', 'is_superuser'), - search_fields = ('username', 'first_name', 'last_name', 'email'), - ) + username = meta.CharField(maxlength=30, unique=True, validator_list=[validators.isAlphaNumeric]) + first_name = meta.CharField(maxlength=30, blank=True) + last_name = meta.CharField(maxlength=30, blank=True) + email = meta.EmailField('e-mail address', blank=True) + password_md5 = meta.CharField('password', maxlength=32, help_text="Use an MD5 hash -- not the raw password.") + is_staff = meta.BooleanField('staff status', help_text="Designates whether the user can log into this admin site.") + is_active = meta.BooleanField('active', default=True) + is_superuser = meta.BooleanField('superuser status') + last_login = meta.DateTimeField(default=meta.LazyDate()) + date_joined = meta.DateTimeField(default=meta.LazyDate()) + groups = meta.ManyToManyField(Group, blank=True, + help_text="In addition to the permissions manually assigned, this user will also get all permissions granted to each group he/she is in.") + user_permissions = meta.ManyToManyField(Permission, blank=True, filter_interface=meta.HORIZONTAL) + class META: + module_constants = { + 'SESSION_KEY': '_auth_user_id', + } + ordering = ('username',) + exceptions = ('SiteProfileNotAvailable',) + admin = meta.Admin( + fields = ( + (None, {'fields': ('username', 'password_md5')}), + ('Personal info', {'fields': ('first_name', 'last_name', 'email')}), + ('Permissions', {'fields': ('is_staff', 'is_active', 'is_superuser', 'user_permissions')}), + ('Important dates', {'fields': ('last_login', 'date_joined')}), + ('Groups', {'fields': ('groups',)}), + ), + list_display = ('username', 'email', 'first_name', 'last_name', 'is_staff'), + list_filter = ('is_staff', 'is_superuser'), + search_fields = ('username', 'first_name', 'last_name', 'email'), + ) def __repr__(self): return self.username @@ -154,7 +149,7 @@ class User(meta.Model): except ImportError: try: module = __import__('django.models.%s' % AUTH_PROFILE_MODULE, [], [], ['']) - self._profile_cache = module.get_object(user_id__exact=self.id) + self._profile_cache = module.get_object(user__id__exact=self.id) except ImportError: raise SiteProfileNotAvailable return self._profile_cache @@ -176,33 +171,30 @@ class User(meta.Model): return ''.join([choice(allowed_chars) for i in range(length)]) class Message(meta.Model): - fields = ( - meta.ForeignKey(User), - meta.TextField('message'), - ) + user = meta.ForeignKey(User) + message = meta.TextField() def __repr__(self): return self.message class LogEntry(meta.Model): - module_name = 'log' - verbose_name_plural = 'log entries' - db_table = 'auth_admin_log' - fields = ( - meta.DateTimeField('action_time', auto_now=True), - meta.ForeignKey(User), - meta.ForeignKey(core.ContentType, name='content_type_id', rel_name='content_type', blank=True, null=True), - meta.TextField('object_id', blank=True, null=True), - meta.CharField('object_repr', maxlength=200), - meta.PositiveSmallIntegerField('action_flag'), - meta.TextField('change_message', blank=True), - ) - ordering = ('-action_time',) - module_constants = { - 'ADDITION': 1, - 'CHANGE': 2, - 'DELETION': 3, - } + action_time = meta.DateTimeField(auto_now=True) + user = meta.ForeignKey(User) + content_type = meta.ForeignKey(core.ContentType, blank=True, null=True) # TODO: content_type_id name? + object_id = meta.TextField(blank=True, null=True) + object_repr = meta.CharField(maxlength=200) + action_flag = meta.PositiveSmallIntegerField() + change_message = meta.TextField(blank=True) + class META: + module_name = 'log' + verbose_name_plural = 'log entries' + db_table = 'auth_admin_log' + ordering = ('-action_time',) + module_constants = { + 'ADDITION': 1, + 'CHANGE': 2, + 'DELETION': 3, + } def __repr__(self): return str(self.action_time) 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 |
