1
0
mirror of https://github.com/django/django.git synced 2025-08-23 18:29:12 +00:00

magic-removal: Renamed 'class META' to 'class Meta' in models

git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@1754 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2005-12-21 02:42:27 +00:00
parent fe524625ed
commit 29fe9598e0
22 changed files with 48 additions and 48 deletions

View File

@ -20,7 +20,7 @@ class LogEntry(models.Model):
action_flag = models.PositiveSmallIntegerField(_('action flag')) action_flag = models.PositiveSmallIntegerField(_('action flag'))
change_message = models.TextField(_('change message'), blank=True) change_message = models.TextField(_('change message'), blank=True)
objects = LogEntryManager() objects = LogEntryManager()
class META: class Meta:
verbose_name = _('log entry') verbose_name = _('log entry')
verbose_name_plural = _('log entries') verbose_name_plural = _('log entries')
db_table = 'django_admin_log' db_table = 'django_admin_log'

View File

@ -84,7 +84,7 @@ class Comment(models.Model):
is_removed = models.BooleanField(_('is removed'), help_text=_('Check this box if the comment is inappropriate. A "This comment has been removed" message will be displayed instead.')) is_removed = models.BooleanField(_('is removed'), help_text=_('Check this box if the comment is inappropriate. A "This comment has been removed" message will be displayed instead.'))
site = models.ForeignKey(core.Site) site = models.ForeignKey(core.Site)
objects = CommentManager() objects = CommentManager()
class META: class Meta:
db_table = 'comments' db_table = 'comments'
verbose_name = _('Comment') verbose_name = _('Comment')
verbose_name_plural = _('Comments') verbose_name_plural = _('Comments')
@ -172,7 +172,7 @@ class FreeComment(models.Model):
# TODO: Change this to is_removed, like Comment # TODO: Change this to is_removed, like Comment
approved = models.BooleanField(_('approved by staff')) approved = models.BooleanField(_('approved by staff'))
site = models.ForeignKey(core.Site) site = models.ForeignKey(core.Site)
class META: class Meta:
db_table = 'comments_free' db_table = 'comments_free'
verbose_name = _('Free comment') verbose_name = _('Free comment')
verbose_name_plural = _('Free comments') verbose_name_plural = _('Free comments')
@ -235,7 +235,7 @@ class KarmaScore(models.Model):
score = models.SmallIntegerField(_('score'), db_index=True) score = models.SmallIntegerField(_('score'), db_index=True)
scored_date = models.DateTimeField(_('score date'), auto_now=True) scored_date = models.DateTimeField(_('score date'), auto_now=True)
objects = KarmaScoreManager() objects = KarmaScoreManager()
class META: class Meta:
verbose_name = _('Karma score') verbose_name = _('Karma score')
verbose_name_plural = _('Karma scores') verbose_name_plural = _('Karma scores')
unique_together = (('user', 'comment'),) unique_together = (('user', 'comment'),)
@ -266,7 +266,7 @@ class UserFlag(models.Model):
comment = models.ForeignKey(Comment) comment = models.ForeignKey(Comment)
flag_date = models.DateTimeField(_('flag date'), auto_now_add=True) flag_date = models.DateTimeField(_('flag date'), auto_now_add=True)
objects = UserFlagManager() objects = UserFlagManager()
class META: class Meta:
db_table = 'comments_user_flags' db_table = 'comments_user_flags'
verbose_name = _('User flag') verbose_name = _('User flag')
verbose_name_plural = _('User flags') verbose_name_plural = _('User flags')
@ -279,7 +279,7 @@ class ModeratorDeletion(models.Model):
user = models.ForeignKey(auth.User, verbose_name='moderator') user = models.ForeignKey(auth.User, verbose_name='moderator')
comment = models.ForeignKey(Comment) comment = models.ForeignKey(Comment)
deletion_date = models.DateTimeField(_('deletion date'), auto_now_add=True) deletion_date = models.DateTimeField(_('deletion date'), auto_now_add=True)
class META: class Meta:
db_table = 'comments_moderator_deletions' db_table = 'comments_moderator_deletions'
verbose_name = _('Moderator deletion') verbose_name = _('Moderator deletion')
verbose_name_plural = _('Moderator deletions') verbose_name_plural = _('Moderator deletions')

View File

@ -13,7 +13,7 @@ class FlatPage(models.Model):
help_text=_("Example: 'flatpages/contact_page'. If this isn't provided, the system will use 'flatpages/default'.")) help_text=_("Example: 'flatpages/contact_page'. If this isn't provided, the system will use 'flatpages/default'."))
registration_required = models.BooleanField(_('registration required'), help_text=_("If this is checked, only logged-in users will be able to view the page.")) registration_required = models.BooleanField(_('registration required'), help_text=_("If this is checked, only logged-in users will be able to view the page."))
sites = models.ManyToManyField(Site) sites = models.ManyToManyField(Site)
class META: class Meta:
db_table = 'django_flatpages' db_table = 'django_flatpages'
verbose_name = _('flat page') verbose_name = _('flat page')
verbose_name_plural = _('flat pages') verbose_name_plural = _('flat pages')

View File

@ -8,7 +8,7 @@ class Redirect(models.Model):
help_text=_("This should be an absolute path, excluding the domain name. Example: '/events/search/'.")) help_text=_("This should be an absolute path, excluding the domain name. Example: '/events/search/'."))
new_path = models.CharField(_('redirect to'), maxlength=200, blank=True, new_path = models.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://'.")) help_text=_("This can be either an absolute path (as above) or a full URL starting with 'http://'."))
class META: class Meta:
verbose_name = _('redirect') verbose_name = _('redirect')
verbose_name_plural = _('redirects') verbose_name_plural = _('redirects')
db_table = 'django_redirects' db_table = 'django_redirects'

View File

@ -699,7 +699,7 @@ def inspectdb(db_name):
if field_type_was_guessed: if field_type_was_guessed:
field_desc += ' # This is a guess!' field_desc += ' # This is a guess!'
yield ' %s' % field_desc yield ' %s' % field_desc
yield ' class META:' yield ' class Meta:'
yield ' db_table = %r' % table_name yield ' db_table = %r' % table_name
yield '' yield ''
inspectdb.help_doc = "Introspects the database tables in the given database and outputs a Django model module." inspectdb.help_doc = "Introspects the database tables in the given database and outputs a Django model module."

View File

@ -30,7 +30,7 @@ class ModelBase(type):
# Create the class. # Create the class.
new_class = type.__new__(cls, name, bases, {'__module__': attrs.pop('__module__')}) new_class = type.__new__(cls, name, bases, {'__module__': attrs.pop('__module__')})
new_class.add_to_class('_meta', Options(attrs.pop('META', None))) new_class.add_to_class('_meta', Options(attrs.pop('Meta', None)))
new_class.add_to_class('DoesNotExist', types.ClassType('DoesNotExist', (ObjectDoesNotExist,), {})) new_class.add_to_class('DoesNotExist', types.ClassType('DoesNotExist', (ObjectDoesNotExist,), {}))
#Figure out the app_label by looking one level up. #Figure out the app_label by looking one level up.

View File

@ -46,7 +46,7 @@ class Options:
for attr_name in DEFAULT_NAMES: for attr_name in DEFAULT_NAMES:
setattr(self, attr_name, meta_attrs.pop(attr_name, getattr(self, attr_name))) setattr(self, attr_name, meta_attrs.pop(attr_name, getattr(self, attr_name)))
if meta_attrs != {}: if meta_attrs != {}:
raise TypeError, "'class META' got invalid attribute(s): %s" % ','.join(meta_attrs.keys()) raise TypeError, "'class Meta' got invalid attribute(s): %s" % ','.join(meta_attrs.keys())
def contribute_to_class(self, cls, name): def contribute_to_class(self, cls, name):
cls._meta = self cls._meta = self

View File

@ -10,7 +10,7 @@ class Permission(models.Model):
name = models.CharField(_('name'), maxlength=50) name = models.CharField(_('name'), maxlength=50)
package = models.ForeignKey(core.Package, db_column='package') package = models.ForeignKey(core.Package, db_column='package')
codename = models.CharField(_('codename'), maxlength=100) codename = models.CharField(_('codename'), maxlength=100)
class META: class Meta:
verbose_name = _('Permission') verbose_name = _('Permission')
verbose_name_plural = _('Permissions') verbose_name_plural = _('Permissions')
unique_together = (('package', 'codename'),) unique_together = (('package', 'codename'),)
@ -22,7 +22,7 @@ class Permission(models.Model):
class Group(models.Model): class Group(models.Model):
name = models.CharField(_('name'), maxlength=80, unique=True) name = models.CharField(_('name'), maxlength=80, unique=True)
permissions = models.ManyToManyField(Permission, blank=True, filter_interface=models.HORIZONTAL) permissions = models.ManyToManyField(Permission, blank=True, filter_interface=models.HORIZONTAL)
class META: class Meta:
verbose_name = _('Group') verbose_name = _('Group')
verbose_name_plural = _('Groups') verbose_name_plural = _('Groups')
ordering = ('name',) ordering = ('name',)
@ -64,7 +64,7 @@ class User(models.Model):
help_text=_("In addition to the permissions manually assigned, this user will also get all permissions granted to each group he/she is in.")) 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 = models.ManyToManyField(Permission, blank=True, filter_interface=models.HORIZONTAL) user_permissions = models.ManyToManyField(Permission, blank=True, filter_interface=models.HORIZONTAL)
objects = UserManager() objects = UserManager()
class META: class Meta:
verbose_name = _('User') verbose_name = _('User')
verbose_name_plural = _('Users') verbose_name_plural = _('Users')
ordering = ('username',) ordering = ('username',)

View File

@ -12,7 +12,7 @@ class Site(models.Model):
domain = models.CharField(_('domain name'), maxlength=100) domain = models.CharField(_('domain name'), maxlength=100)
name = models.CharField(_('display name'), maxlength=50) name = models.CharField(_('display name'), maxlength=50)
objects = SiteManager() objects = SiteManager()
class META: class Meta:
verbose_name = _('site') verbose_name = _('site')
verbose_name_plural = _('sites') verbose_name_plural = _('sites')
db_table = 'sites' db_table = 'sites'
@ -28,7 +28,7 @@ class Site(models.Model):
class Package(models.Model): class Package(models.Model):
label = models.CharField(_('label'), maxlength=20, primary_key=True) label = models.CharField(_('label'), maxlength=20, primary_key=True)
name = models.CharField(_('name'), maxlength=30, unique=True) name = models.CharField(_('name'), maxlength=30, unique=True)
class META: class Meta:
verbose_name = _('package') verbose_name = _('package')
verbose_name_plural = _('packages') verbose_name_plural = _('packages')
db_table = 'packages' db_table = 'packages'
@ -41,7 +41,7 @@ class ContentType(models.Model):
name = models.CharField(_('name'), maxlength=100) name = models.CharField(_('name'), maxlength=100)
package = models.ForeignKey(Package, db_column='package') package = models.ForeignKey(Package, db_column='package')
python_module_name = models.CharField(_('python module name'), maxlength=50) python_module_name = models.CharField(_('python module name'), maxlength=50)
class META: class Meta:
verbose_name = _('content type') verbose_name = _('content type')
verbose_name_plural = _('content types') verbose_name_plural = _('content types')
db_table = 'content_types' db_table = 'content_types'
@ -98,7 +98,7 @@ class Session(models.Model):
session_data = models.TextField(_('session data')) session_data = models.TextField(_('session data'))
expire_date = models.DateTimeField(_('expire date')) expire_date = models.DateTimeField(_('expire date'))
objects = SessionManager() objects = SessionManager()
class META: class Meta:
verbose_name = _('session') verbose_name = _('session')
verbose_name_plural = _('sessions') verbose_name_plural = _('sessions')
module_constants = { module_constants = {

View File

@ -395,20 +395,20 @@ Custom permissions
------------------ ------------------
To create custom permissions for a given model object, use the ``permissions`` To create custom permissions for a given model object, use the ``permissions``
`model META attribute`_. `model Meta attribute`_.
This example model creates three custom permissions:: This example model creates three custom permissions::
class USCitizen(meta.Model): class USCitizen(meta.Model):
# ... # ...
class META: class Meta:
permissions = ( permissions = (
("can_drive", "Can drive"), ("can_drive", "Can drive"),
("can_vote", "Can vote in elections"), ("can_vote", "Can vote in elections"),
("can_drink", "Can drink alcohol"), ("can_drink", "Can drink alcohol"),
) )
.. _model META attribute: http://www.djangoproject.com/documentation/model_api/#meta-options .. _model Meta attribute: http://www.djangoproject.com/documentation/model_api/#meta-options
API reference API reference
------------- -------------

View File

@ -32,7 +32,7 @@ this document, we'll be working with the following model, a "place" object::
state = meta.USStateField(), state = meta.USStateField(),
zip_code = meta.CharField(maxlength=5, blank=True), zip_code = meta.CharField(maxlength=5, blank=True),
place_type = meta.IntegerField(choices=PLACE_TYPES) place_type = meta.IntegerField(choices=PLACE_TYPES)
class META: class Meta:
admin = meta.Admin() admin = meta.Admin()
def __repr__(self): def __repr__(self):

View File

@ -150,14 +150,14 @@ If you don't like the verbose name ``gettext_lazy``, you can just alias it as
Always use lazy translations in `Django models`_. And it's a good idea to add Always use lazy translations in `Django models`_. And it's a good idea to add
translations for the field names and table names, too. This means writing translations for the field names and table names, too. This means writing
explicit ``verbose_name`` and ``verbose_name_plural`` options in the ``META`` explicit ``verbose_name`` and ``verbose_name_plural`` options in the ``Meta``
class, though:: class, though::
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
class MyThing(meta.Model): class MyThing(meta.Model):
name = meta.CharField(_('name'), help_text=_('This is the help text')) name = meta.CharField(_('name'), help_text=_('This is the help text'))
class META: class Meta:
verbose_name = _('my thing') verbose_name = _('my thing')
verbose_name_plural = _('mythings') verbose_name_plural = _('mythings')

View File

@ -10,7 +10,7 @@ The basics:
* Each model is a Python class that subclasses ``django.core.meta.Model``. * Each model is a Python class that subclasses ``django.core.meta.Model``.
* Each attribute of the model represents a database field. * Each attribute of the model represents a database field.
* Model metadata (non-field information) goes in an inner class named ``META``. * Model metadata (non-field information) goes in an inner class named ``Meta``.
A companion to this document is the `official repository of model examples`_. A companion to this document is the `official repository of model examples`_.
@ -21,7 +21,7 @@ Field objects
The most important part of a model is the list of database fields it defines. The most important part of a model is the list of database fields it defines.
Fields are defined by class attributes. Each class attribute in a model, aside Fields are defined by class attributes. Each class attribute in a model, aside
from the optional inner ``class META``, should be an instance of a from the optional inner ``class Meta``, should be an instance of a
``meta.Field`` subclass. ``meta.Field`` subclass.
In this example, there are two fields, ``first_name`` and ``last_name`` :: In this example, there are two fields, ``first_name`` and ``last_name`` ::
@ -700,23 +700,23 @@ See the `One-to-one relationship model example`_ for a full example.
.. _One-to-one relationship model example: http://www.djangoproject.com/documentation/models/one_to_one/ .. _One-to-one relationship model example: http://www.djangoproject.com/documentation/models/one_to_one/
META options Meta options
============ ============
Give your model metadata by using an inner ``"class META"``, like so:: Give your model metadata by using an inner ``"class Meta"``, like so::
class Foo(meta.Model): class Foo(meta.Model):
bar = meta.CharField(maxlength=30) bar = meta.CharField(maxlength=30)
# ... # ...
class META: class Meta:
admin = meta.Admin() admin = meta.Admin()
# ... # ...
Model metadata is "anything that's not a field" -- ordering options, admin Model metadata is "anything that's not a field" -- ordering options, admin
options, etc. options, etc.
Here's a list of all possible ``META`` options. No options are required. Adding Here's a list of all possible ``Meta`` options. No options are required. Adding
``class META`` to a model is completely optional. ``class Meta`` to a model is completely optional.
``admin`` ``admin``
A ``meta.Admin`` object; see `Admin options`_. If this field is given, the A ``meta.Admin`` object; see `Admin options`_. If this field is given, the
@ -943,7 +943,7 @@ object, which takes the following parameters. All are optional.
if one of the ``list_display`` fields is a ``ForeignKey``. if one of the ``list_display`` fields is a ``ForeignKey``.
``ordering`` ``ordering``
A list or tuple (see the `META options`_, above) that gives a A list or tuple (see the `Meta options`_, above) that gives a
different ordering for the admin change list. If this isn't given, the different ordering for the admin change list. If this isn't given, the
model's default ordering will be used. model's default ordering will be used.

View File

@ -138,7 +138,7 @@ model classes::
headline = meta.CharField(maxlength=200) headline = meta.CharField(maxlength=200)
article = meta.TextField() article = meta.TextField()
reporter = meta.ForeignKey(Reporter) reporter = meta.ForeignKey(Reporter)
class META: class Meta:
admin = meta.Admin() admin = meta.Admin()
The philosophy here is that your site is edited by a staff, or a client, or The philosophy here is that your site is edited by a staff, or a client, or

View File

@ -93,15 +93,15 @@ But where's our poll app? It's not displayed on the admin index page.
Just one thing to do: We need to specify in the ``polls.Poll`` model that Poll Just one thing to do: We need to specify in the ``polls.Poll`` model that Poll
objects have an admin interface. Edit the ``myproject/apps/polls/models/polls.py`` objects have an admin interface. Edit the ``myproject/apps/polls/models/polls.py``
file and make the following change to add an inner ``META`` class with an file and make the following change to add an inner ``Meta`` class with an
``admin`` attribute:: ``admin`` attribute::
class Poll(meta.Model): class Poll(meta.Model):
# ... # ...
class META: class Meta:
admin = meta.Admin() admin = meta.Admin()
The ``class META`` contains all non-field metadata about this model. The ``class Meta`` contains all non-field metadata about this model.
Now reload the Django admin page to see your changes. Note that you don't have Now reload the Django admin page to see your changes. Note that you don't have
to restart the development server -- it auto-reloads code. to restart the development server -- it auto-reloads code.
@ -227,7 +227,7 @@ Here's what that would look like::
class Choice(meta.Model): class Choice(meta.Model):
# ... # ...
class META: class Meta:
admin = meta.Admin() admin = meta.Admin()
Now "Choices" is an available option in the Django admin. The "Add choice" form Now "Choices" is an available option in the Django admin. The "Add choice" form
@ -311,7 +311,7 @@ on the change list page for the object::
class Poll(meta.Model): class Poll(meta.Model):
# ... # ...
class META: class Meta:
admin = meta.Admin( admin = meta.Admin(
# ... # ...
list_display = ('question', 'pub_date'), list_display = ('question', 'pub_date'),

View File

@ -11,7 +11,7 @@ class Employee(models.Model):
employee_code = models.CharField(maxlength=10, primary_key=True) employee_code = models.CharField(maxlength=10, primary_key=True)
first_name = models.CharField(maxlength=20) first_name = models.CharField(maxlength=20)
last_name = models.CharField(maxlength=20) last_name = models.CharField(maxlength=20)
class META: class Meta:
ordering = ('last_name', 'first_name') ordering = ('last_name', 'first_name')
def __repr__(self): def __repr__(self):
@ -20,7 +20,7 @@ class Employee(models.Model):
class Business(models.Model): class Business(models.Model):
name = models.CharField(maxlength=20, primary_key=True) name = models.CharField(maxlength=20, primary_key=True)
employees = models.ManyToManyField(Employee) employees = models.ManyToManyField(Employee)
class META: class Meta:
verbose_name_plural = 'businesses' verbose_name_plural = 'businesses'
module_name = 'businesses' module_name = 'businesses'

View File

@ -13,7 +13,7 @@ from django.db import models
class Article(models.Model): class Article(models.Model):
headline = models.CharField(maxlength=100) headline = models.CharField(maxlength=100)
pub_date = models.DateTimeField() pub_date = models.DateTimeField()
class META: class Meta:
get_latest_by = 'pub_date' get_latest_by = 'pub_date'
def __repr__(self): def __repr__(self):

View File

@ -9,7 +9,7 @@ from django.db import models
class Article(models.Model): class Article(models.Model):
headline = models.CharField(maxlength=100) headline = models.CharField(maxlength=100)
pub_date = models.DateTimeField() pub_date = models.DateTimeField()
class META: class Meta:
ordering = ('-pub_date', 'headline') ordering = ('-pub_date', 'headline')
def __repr__(self): def __repr__(self):

View File

@ -14,7 +14,7 @@ from django.db import models
class Category(models.Model): class Category(models.Model):
name = models.CharField(maxlength=20) name = models.CharField(maxlength=20)
class META: class Meta:
ordering = ('name',) ordering = ('name',)
def __repr__(self): def __repr__(self):
@ -27,7 +27,7 @@ class Article(models.Model):
singular='primary_category', related_name='primary_article') singular='primary_category', related_name='primary_article')
secondary_categories = models.ManyToManyField(Category, secondary_categories = models.ManyToManyField(Category,
singular='secondary_category', related_name='secondary_article') singular='secondary_category', related_name='secondary_article')
class META: class Meta:
ordering = ('pub_date',) ordering = ('pub_date',)
def __repr__(self): def __repr__(self):

View File

@ -11,7 +11,7 @@ from django.db import models
class Article(models.Model): class Article(models.Model):
headline = models.CharField(maxlength=50) headline = models.CharField(maxlength=50)
pub_date = models.DateTimeField() pub_date = models.DateTimeField()
class META: class Meta:
ordering = ('pub_date',) ordering = ('pub_date',)
def __repr__(self): def __repr__(self):

View File

@ -18,7 +18,7 @@ from django.db import models
class Article(models.Model): class Article(models.Model):
headline = models.CharField(maxlength=100) headline = models.CharField(maxlength=100)
pub_date = models.DateTimeField() pub_date = models.DateTimeField()
class META: class Meta:
ordering = ('-pub_date', 'headline') ordering = ('-pub_date', 'headline')
def __repr__(self): def __repr__(self):

View File

@ -18,7 +18,7 @@ class Thing(models.Model):
having = models.CharField(maxlength=1) having = models.CharField(maxlength=1)
where = models.CharField(maxlength=1) where = models.CharField(maxlength=1)
has_hyphen = models.CharField(maxlength=1, db_column='has-hyphen') has_hyphen = models.CharField(maxlength=1, db_column='has-hyphen')
class META: class Meta:
db_table = 'select' db_table = 'select'
def __repr__(self): def __repr__(self):