Loading docs/intro/overview.txt +4 −4 Original line number Diff line number Diff line Loading @@ -31,7 +31,7 @@ the file ``mysite/news/models.py``:: return self.full_name class Article(models.Model): pub_date = models.DateTimeField() pub_date = models.DateField() headline = models.CharField(max_length=200) content = models.TextField() reporter = models.ForeignKey(Reporter) Loading Loading @@ -96,8 +96,8 @@ access your data. The API is created on the fly, no code generation necessary:: DoesNotExist: Reporter matching query does not exist. Lookup parameters were {'id': 2} # Create an article. >>> from datetime import datetime >>> a = Article(pub_date=datetime.now(), headline='Django is cool', >>> from datetime import date >>> a = Article(pub_date=date.today(), headline='Django is cool', ... content='Yeah.', reporter=r) >>> a.save() Loading Loading @@ -140,7 +140,7 @@ as registering your model in the admin site:: from django.db import models class Article(models.Model): pub_date = models.DateTimeField() pub_date = models.DateField() headline = models.CharField(max_length=200) content = models.TextField() reporter = models.ForeignKey(Reporter) Loading docs/ref/contrib/comments/moderation.txt +4 −4 Original line number Diff line number Diff line Loading @@ -36,7 +36,7 @@ following model, which would represent entries in a Weblog:: class Entry(models.Model): title = models.CharField(maxlength=250) body = models.TextField() pub_date = models.DateTimeField() pub_date = models.DateField() enable_comments = models.BooleanField() Now, suppose that we want the following steps to be applied whenever a Loading docs/ref/models/fields.txt +2 −2 Original line number Diff line number Diff line Loading @@ -983,10 +983,10 @@ define the details of how the relation works. this with functions from the Python ``datetime`` module to limit choices of objects by date. For example:: limit_choices_to = {'pub_date__lte': datetime.now} limit_choices_to = {'pub_date__lte': datetime.date.today} only allows the choice of related objects with a ``pub_date`` before the current date/time to be chosen. current date to be chosen. Instead of a dictionary this can also be a :class:`~django.db.models.Q` object for more :ref:`complex queries <complex-lookups-with-q>`. However, Loading docs/ref/models/instances.txt +1 −1 Original line number Diff line number Diff line Loading @@ -135,7 +135,7 @@ access to more than a single field:: raise ValidationError('Draft entries may not have a publication date.') # Set the pub_date for published items if it hasn't been set already. if self.status == 'published' and self.pub_date is None: self.pub_date = datetime.datetime.now() self.pub_date = datetime.date.today() Any :exc:`~django.core.exceptions.ValidationError` exceptions raised by ``Model.clean()`` will be stored in a special key error dictionary key, Loading docs/ref/models/querysets.txt +12 −1 Original line number Diff line number Diff line Loading @@ -1945,6 +1945,17 @@ SQL equivalent:: You can use ``range`` anywhere you can use ``BETWEEN`` in SQL — for dates, numbers and even characters. .. warning:: Filtering a ``DateTimeField`` with dates won't include items on the last day, because the bounds are interpreted as "0am on the given date". If ``pub_date`` was a ``DateTimeField``, the above expression would be turned into this SQL:: SELECT ... WHERE pub_date BETWEEN '2005-01-01 00:00:00' and '2005-03-31 00:00:00'; Generally speaking, you can't mix dates and datetimes. .. fieldlookup:: year year Loading @@ -1958,7 +1969,7 @@ Example:: SQL equivalent:: SELECT ... WHERE pub_date BETWEEN '2005-01-01' AND '2005-12-31 23:59:59.999999'; SELECT ... WHERE pub_date BETWEEN '2005-01-01' AND '2005-12-31'; (The exact SQL syntax varies for each database engine.) Loading Loading
docs/intro/overview.txt +4 −4 Original line number Diff line number Diff line Loading @@ -31,7 +31,7 @@ the file ``mysite/news/models.py``:: return self.full_name class Article(models.Model): pub_date = models.DateTimeField() pub_date = models.DateField() headline = models.CharField(max_length=200) content = models.TextField() reporter = models.ForeignKey(Reporter) Loading Loading @@ -96,8 +96,8 @@ access your data. The API is created on the fly, no code generation necessary:: DoesNotExist: Reporter matching query does not exist. Lookup parameters were {'id': 2} # Create an article. >>> from datetime import datetime >>> a = Article(pub_date=datetime.now(), headline='Django is cool', >>> from datetime import date >>> a = Article(pub_date=date.today(), headline='Django is cool', ... content='Yeah.', reporter=r) >>> a.save() Loading Loading @@ -140,7 +140,7 @@ as registering your model in the admin site:: from django.db import models class Article(models.Model): pub_date = models.DateTimeField() pub_date = models.DateField() headline = models.CharField(max_length=200) content = models.TextField() reporter = models.ForeignKey(Reporter) Loading
docs/ref/contrib/comments/moderation.txt +4 −4 Original line number Diff line number Diff line Loading @@ -36,7 +36,7 @@ following model, which would represent entries in a Weblog:: class Entry(models.Model): title = models.CharField(maxlength=250) body = models.TextField() pub_date = models.DateTimeField() pub_date = models.DateField() enable_comments = models.BooleanField() Now, suppose that we want the following steps to be applied whenever a Loading
docs/ref/models/fields.txt +2 −2 Original line number Diff line number Diff line Loading @@ -983,10 +983,10 @@ define the details of how the relation works. this with functions from the Python ``datetime`` module to limit choices of objects by date. For example:: limit_choices_to = {'pub_date__lte': datetime.now} limit_choices_to = {'pub_date__lte': datetime.date.today} only allows the choice of related objects with a ``pub_date`` before the current date/time to be chosen. current date to be chosen. Instead of a dictionary this can also be a :class:`~django.db.models.Q` object for more :ref:`complex queries <complex-lookups-with-q>`. However, Loading
docs/ref/models/instances.txt +1 −1 Original line number Diff line number Diff line Loading @@ -135,7 +135,7 @@ access to more than a single field:: raise ValidationError('Draft entries may not have a publication date.') # Set the pub_date for published items if it hasn't been set already. if self.status == 'published' and self.pub_date is None: self.pub_date = datetime.datetime.now() self.pub_date = datetime.date.today() Any :exc:`~django.core.exceptions.ValidationError` exceptions raised by ``Model.clean()`` will be stored in a special key error dictionary key, Loading
docs/ref/models/querysets.txt +12 −1 Original line number Diff line number Diff line Loading @@ -1945,6 +1945,17 @@ SQL equivalent:: You can use ``range`` anywhere you can use ``BETWEEN`` in SQL — for dates, numbers and even characters. .. warning:: Filtering a ``DateTimeField`` with dates won't include items on the last day, because the bounds are interpreted as "0am on the given date". If ``pub_date`` was a ``DateTimeField``, the above expression would be turned into this SQL:: SELECT ... WHERE pub_date BETWEEN '2005-01-01 00:00:00' and '2005-03-31 00:00:00'; Generally speaking, you can't mix dates and datetimes. .. fieldlookup:: year year Loading @@ -1958,7 +1969,7 @@ Example:: SQL equivalent:: SELECT ... WHERE pub_date BETWEEN '2005-01-01' AND '2005-12-31 23:59:59.999999'; SELECT ... WHERE pub_date BETWEEN '2005-01-01' AND '2005-12-31'; (The exact SQL syntax varies for each database engine.) Loading