1
0
mirror of https://github.com/django/django.git synced 2025-10-26 07:06:08 +00:00

magic-removal: Moved django.core.meta to django.db.models

git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@1631 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty
2005-12-14 05:02:51 +00:00
parent 55933c86e7
commit d0fabc0499
39 changed files with 338 additions and 331 deletions

View File

@@ -4,11 +4,11 @@
This is a basic model with only two non-primary-key fields.
"""
from django.core import meta
from django.db import models
class Article(meta.Model):
headline = meta.CharField(maxlength=100, default='Default headline')
pub_date = meta.DateTimeField()
class Article(models.Model):
headline = models.CharField(maxlength=100, default='Default headline')
pub_date = models.DateTimeField()
API_TESTS = """
# No articles are in the system yet.

View File

@@ -9,16 +9,16 @@ For each field that has ``choices``, a model instance gets a
field. This method returns the "human-readable" value of the field.
"""
from django.core import meta
from django.db import models
GENDER_CHOICES = (
('M', 'Male'),
('F', 'Female'),
)
class Person(meta.Model):
name = meta.CharField(maxlength=20)
gender = meta.CharField(maxlength=1, choices=GENDER_CHOICES)
class Person(models.Model):
name = models.CharField(maxlength=20)
gender = models.CharField(maxlength=1, choices=GENDER_CHOICES)
def __repr__(self):
return self.name

View File

@@ -6,11 +6,11 @@ If your database column name is different than your model attribute, use the
name, in API usage.
"""
from django.core import meta
from django.db import models
class Person(meta.Model):
first_name = meta.CharField(maxlength=30, db_column='firstname')
last_name = meta.CharField(maxlength=30, db_column='last')
class Person(models.Model):
first_name = models.CharField(maxlength=30, db_column='firstname')
last_name = models.CharField(maxlength=30, db_column='last')
def __repr__(self):
return '%s %s' % (self.first_name, self.last_name)

View File

@@ -4,11 +4,11 @@
Any method you add to a model will be available to instances.
"""
from django.core import meta
from django.db import models
class Article(meta.Model):
headline = meta.CharField(maxlength=100)
pub_date = meta.DateField()
class Article(models.Model):
headline = models.CharField(maxlength=100)
pub_date = models.DateField()
def __repr__(self):
return self.headline

View File

@@ -5,21 +5,21 @@ By default, Django adds an ``"id"`` field to each model. But you can override
this behavior by explicitly adding ``primary_key=True`` to a field.
"""
from django.core import meta
from django.db import models
class Employee(meta.Model):
employee_code = meta.CharField(maxlength=10, primary_key=True)
first_name = meta.CharField(maxlength=20)
last_name = meta.CharField(maxlength=20)
class Employee(models.Model):
employee_code = models.CharField(maxlength=10, primary_key=True)
first_name = models.CharField(maxlength=20)
last_name = models.CharField(maxlength=20)
class META:
ordering = ('last_name', 'first_name')
def __repr__(self):
return "%s %s" % (self.first_name, self.last_name)
class Business(meta.Model):
name = meta.CharField(maxlength=20, primary_key=True)
employees = meta.ManyToManyField(Employee)
class Business(models.Model):
name = models.CharField(maxlength=20, primary_key=True)
employees = models.ManyToManyField(Employee)
class META:
verbose_name_plural = 'businesses'
module_name = 'businesses'

View File

@@ -8,11 +8,11 @@ object in the database according to that field. "Latest" means "having the
date farthest into the future."
"""
from django.core import meta
from django.db import models
class Article(meta.Model):
headline = meta.CharField(maxlength=100)
pub_date = meta.DateTimeField()
class Article(models.Model):
headline = models.CharField(maxlength=100)
pub_date = models.DateTimeField()
class META:
get_latest_by = 'pub_date'

View File

@@ -4,11 +4,11 @@
This demonstrates features of the database API.
"""
from django.core import meta
from django.db import models
class Article(meta.Model):
headline = meta.CharField(maxlength=100)
pub_date = meta.DateTimeField()
class Article(models.Model):
headline = models.CharField(maxlength=100)
pub_date = models.DateTimeField()
class META:
ordering = ('-pub_date', 'headline')

View File

@@ -10,26 +10,26 @@ which specifies the ``Reporter``'s position for the given article (e.g. "Staff
writer").
"""
from django.core import meta
from django.db import models
class Reporter(meta.Model):
first_name = meta.CharField(maxlength=30)
last_name = meta.CharField(maxlength=30)
class Reporter(models.Model):
first_name = models.CharField(maxlength=30)
last_name = models.CharField(maxlength=30)
def __repr__(self):
return "%s %s" % (self.first_name, self.last_name)
class Article(meta.Model):
headline = meta.CharField(maxlength=100)
pub_date = meta.DateField()
class Article(models.Model):
headline = models.CharField(maxlength=100)
pub_date = models.DateField()
def __repr__(self):
return self.headline
class Writer(meta.Model):
reporter = meta.ForeignKey(Reporter)
article = meta.ForeignKey(Article)
position = meta.CharField(maxlength=100)
class Writer(models.Model):
reporter = models.ForeignKey(Reporter)
article = models.ForeignKey(Article)
position = models.CharField(maxlength=100)
def __repr__(self):
return '%r (%s)' % (self.get_reporter(), self.position)

View File

@@ -10,22 +10,22 @@ Set ``singular`` to designate what the category object is called. This is
required if a model has multiple ``ManyToManyFields`` to the same object.
"""
from django.core import meta
from django.db import models
class Category(meta.Model):
name = meta.CharField(maxlength=20)
class Category(models.Model):
name = models.CharField(maxlength=20)
class META:
ordering = ('name',)
def __repr__(self):
return self.name
class Article(meta.Model):
headline = meta.CharField(maxlength=50)
pub_date = meta.DateTimeField()
primary_categories = meta.ManyToManyField(Category,
class Article(models.Model):
headline = models.CharField(maxlength=50)
pub_date = models.DateTimeField()
primary_categories = models.ManyToManyField(Category,
singular='primary_category', related_name='primary_article')
secondary_categories = meta.ManyToManyField(Category,
secondary_categories = models.ManyToManyField(Category,
singular='secondary_category', related_name='secondary_article')
class META:
ordering = ('pub_date',)

View File

@@ -10,11 +10,11 @@ In this example, a ``Category`` is related to itself. That is, each
Set ``related_name`` to designate what the reverse relationship is called.
"""
from django.core import meta
from django.db import models
class Category(meta.Model):
name = meta.CharField(maxlength=20)
parent = meta.ForeignKey('self', null=True, related_name='child')
class Category(models.Model):
name = models.CharField(maxlength=20)
parent = models.ForeignKey('self', null=True, related_name='child')
def __repr__(self):
return self.name

View File

@@ -7,12 +7,12 @@ which are other ``Person`` objects.
Set ``related_name`` to designate what the reverse relationship is called.
"""
from django.core import meta
from django.db import models
class Person(meta.Model):
full_name = meta.CharField(maxlength=20)
mother = meta.ForeignKey('self', null=True, related_name='mothers_child')
father = meta.ForeignKey('self', null=True, related_name='fathers_child')
class Person(models.Model):
full_name = models.CharField(maxlength=20)
mother = models.ForeignKey('self', null=True, related_name='mothers_child')
father = models.ForeignKey('self', null=True, related_name='fathers_child')
def __repr__(self):
return self.full_name

View File

@@ -7,17 +7,17 @@ In this example, an article can be published in multiple publications,
and a publication has multiple articles.
"""
from django.core import meta
from django.db import models
class Publication(meta.Model):
title = meta.CharField(maxlength=30)
class Publication(models.Model):
title = models.CharField(maxlength=30)
def __repr__(self):
return self.title
class Article(meta.Model):
headline = meta.CharField(maxlength=100)
publications = meta.ManyToManyField(Publication)
class Article(models.Model):
headline = models.CharField(maxlength=100)
publications = models.ManyToManyField(Publication)
def __repr__(self):
return self.headline

View File

@@ -4,20 +4,20 @@
To define a many-to-one relationship, use ``ForeignKey()`` .
"""
from django.core import meta
from django.db import models
class Reporter(meta.Model):
first_name = meta.CharField(maxlength=30)
last_name = meta.CharField(maxlength=30)
email = meta.EmailField()
class Reporter(models.Model):
first_name = models.CharField(maxlength=30)
last_name = models.CharField(maxlength=30)
email = models.EmailField()
def __repr__(self):
return "%s %s" % (self.first_name, self.last_name)
class Article(meta.Model):
headline = meta.CharField(maxlength=100)
pub_date = meta.DateField()
reporter = meta.ForeignKey(Reporter)
class Article(models.Model):
headline = models.CharField(maxlength=100)
pub_date = models.DateField()
reporter = models.ForeignKey(Reporter)
def __repr__(self):
return self.headline

View File

@@ -5,17 +5,17 @@ To define a many-to-one relationship that can have a null foreign key, use
``ForeignKey()`` with ``null=True`` .
"""
from django.core import meta
from django.db import models
class Reporter(meta.Model):
name = meta.CharField(maxlength=30)
class Reporter(models.Model):
name = models.CharField(maxlength=30)
def __repr__(self):
return self.name
class Article(meta.Model):
headline = meta.CharField(maxlength=100)
reporter = meta.ForeignKey(Reporter, null=True)
class Article(models.Model):
headline = models.CharField(maxlength=100)
reporter = models.ForeignKey(Reporter, null=True)
def __repr__(self):
return self.headline

View File

@@ -6,26 +6,26 @@ To define a one-to-one relationship, use ``OneToOneField()``.
In this example, a ``Place`` optionally can be a ``Restaurant``.
"""
from django.core import meta
from django.db import models
class Place(meta.Model):
name = meta.CharField(maxlength=50)
address = meta.CharField(maxlength=80)
class Place(models.Model):
name = models.CharField(maxlength=50)
address = models.CharField(maxlength=80)
def __repr__(self):
return "%s the place" % self.name
class Restaurant(meta.Model):
place = meta.OneToOneField(Place)
serves_hot_dogs = meta.BooleanField()
serves_pizza = meta.BooleanField()
class Restaurant(models.Model):
place = models.OneToOneField(Place)
serves_hot_dogs = models.BooleanField()
serves_pizza = models.BooleanField()
def __repr__(self):
return "%s the restaurant" % self.get_place().name
class Waiter(meta.Model):
restaurant = meta.ForeignKey(Restaurant)
name = meta.CharField(maxlength=50)
class Waiter(models.Model):
restaurant = models.ForeignKey(Restaurant)
name = models.CharField(maxlength=50)
def __repr__(self):
return "%s the waiter at %r" % (self.name, self.get_restaurant())

View File

@@ -3,14 +3,14 @@
To perform an OR lookup, or a lookup that combines ANDs and ORs, use the
``complex`` keyword argument, and pass it an expression of clauses using the
variable ``django.core.meta.Q``.
variable ``django.db.models.Q``.
"""
from django.core import meta
from django.db import models
class Article(meta.Model):
headline = meta.CharField(maxlength=50)
pub_date = meta.DateTimeField()
class Article(models.Model):
headline = models.CharField(maxlength=50)
pub_date = models.DateTimeField()
class META:
ordering = ('pub_date',)
@@ -19,7 +19,7 @@ class Article(meta.Model):
API_TESTS = """
>>> from datetime import datetime
>>> from django.core.meta import Q
>>> from django.db.models import Q
>>> a1 = Article(headline='Hello', pub_date=datetime(2005, 11, 27))
>>> a1.save()

View File

@@ -13,11 +13,11 @@ The ordering attribute is not required. If you leave it off, ordering will be
undefined -- not random, just undefined.
"""
from django.core import meta
from django.db import models
class Article(meta.Model):
headline = meta.CharField(maxlength=100)
pub_date = meta.DateTimeField()
class Article(models.Model):
headline = models.CharField(maxlength=100)
pub_date = models.DateTimeField()
class META:
ordering = ('-pub_date', 'headline')

View File

@@ -2,11 +2,11 @@
22. Using properties on models
"""
from django.core import meta
from django.db import models
class Person(meta.Model):
first_name = meta.CharField(maxlength=30)
last_name = meta.CharField(maxlength=30)
class Person(models.Model):
first_name = models.CharField(maxlength=30)
last_name = models.CharField(maxlength=30)
def _get_full_name(self):
return "%s %s" % (self.first_name, self.last_name)

View File

@@ -8,11 +8,11 @@ because objects' representations are used throughout Django's
automatically-generated admin.
"""
from django.core import meta
from django.db import models
class Article(meta.Model):
headline = meta.CharField(maxlength=100)
pub_date = meta.DateTimeField()
class Article(models.Model):
headline = models.CharField(maxlength=100)
pub_date = models.DateTimeField()
def __repr__(self):
return self.headline

View File

@@ -7,17 +7,17 @@ appropriately behind the scenes, so your database won't complain about
reserved-name usage.
"""
from django.core import meta
from django.db import models
class Thing(meta.Model):
when = meta.CharField(maxlength=1, primary_key=True)
join = meta.CharField(maxlength=1)
like = meta.CharField(maxlength=1)
drop = meta.CharField(maxlength=1)
alter = meta.CharField(maxlength=1)
having = meta.CharField(maxlength=1)
where = meta.CharField(maxlength=1)
has_hyphen = meta.CharField(maxlength=1, db_column='has-hyphen')
class Thing(models.Model):
when = models.CharField(maxlength=1, primary_key=True)
join = models.CharField(maxlength=1)
like = models.CharField(maxlength=1)
drop = models.CharField(maxlength=1)
alter = models.CharField(maxlength=1)
having = models.CharField(maxlength=1)
where = models.CharField(maxlength=1)
has_hyphen = models.CharField(maxlength=1, db_column='has-hyphen')
class META:
db_table = 'select'

View File

@@ -10,11 +10,11 @@ Django provides hooks for executing arbitrary code around ``save()`` and
* ``_post_delete()`` is called after an object is deleted.
"""
from django.core import meta
from django.db import models
class Person(meta.Model):
first_name = meta.CharField(maxlength=20)
last_name = meta.CharField(maxlength=20)
class Person(models.Model):
first_name = models.CharField(maxlength=20)
last_name = models.CharField(maxlength=20)
def __repr__(self):
return "%s %s" % (self.first_name, self.last_name)

View File

@@ -5,7 +5,7 @@ You can subclass another model to create a copy of it that behaves slightly
differently.
"""
from django.core import meta
from django.db import models
# From the "Bare-bones model" example
from modeltests.basic.models import Article
@@ -19,7 +19,7 @@ from modeltests.ordering.models import Article as ArticleWithOrdering
# This uses all fields and metadata from Article and
# adds a "section" field.
class ArticleWithSection(Article):
section = meta.CharField(maxlength=30)
section = models.CharField(maxlength=30)
# This uses all fields and metadata from Article but
# removes the "pub_date" field.
@@ -30,15 +30,15 @@ class ArticleWithoutPubDate(Article):
# This uses all fields and metadata from Article but
# overrides the "pub_date" field.
class ArticleWithFieldOverride(Article):
pub_date = meta.DateField() # overrides the old field, a DateTimeField
pub_date = models.DateField() # overrides the old field, a DateTimeField
# No need to add remove_fields = ('pub_date',)
# This uses all fields and metadata from ArticleWithRepr and
# makes a few additions/changes.
class ArticleWithManyChanges(ArticleWithRepr):
section = meta.CharField(maxlength=30)
is_popular = meta.BooleanField()
pub_date = meta.DateField() # overrides the old field, a DateTimeField
section = models.CharField(maxlength=30)
is_popular = models.BooleanField()
pub_date = models.DateField() # overrides the old field, a DateTimeField
# This uses all fields from ArticleWithOrdering but
# changes the ordering parameter.
@@ -47,10 +47,10 @@ class ArticleWithChangedMeta(ArticleWithOrdering):
ordering = ('headline', 'pub_date')
class NoModuleNameFirst(Article):
section = meta.CharField(maxlength=30)
section = models.CharField(maxlength=30)
class NoModuleNameSecond(Article):
section = meta.CharField(maxlength=30)
section = models.CharField(maxlength=30)
API_TESTS = """
# No data is in the system yet.