@@ -22,7 +22,7 @@ objects** as class attributes to the document class::
2222
2323 class Page(Document):
2424 title = StringField(max_length=200, required=True)
25- date_modified = DateTimeField(default=datetime.datetime.utcnow )
25+ date_modified = DateTimeField(default=datetime.datetime.now(datetime.timezone.utc) )
2626
2727As BSON (the binary format for storing data in mongodb) is order dependent,
2828documents are serialized based on their field order.
@@ -274,7 +274,7 @@ store; in this situation a :class:`~mongoengine.fields.DictField` is appropriate
274274 user = ReferenceField(User)
275275 answers = DictField()
276276
277- survey_response = SurveyResponse(date=datetime.utcnow( ), user=request.user)
277+ survey_response = SurveyResponse(date=datetime.datetime.now(datetime.timezone.utc ), user=request.user)
278278 response_form = ResponseForm(request.POST)
279279 survey_response.answers = response_form.cleaned_data()
280280 survey_response.save()
@@ -689,7 +689,7 @@ collection after a given period. See the official
689689documentation for more information. A common usecase might be session data::
690690
691691 class Session(Document):
692- created = DateTimeField(default=datetime.utcnow )
692+ created = DateTimeField(default=datetime.datetime.now(datetime.timezone.utc) )
693693 meta = {
694694 'indexes': [
695695 {'fields': ['created'], 'expireAfterSeconds': 3600}
@@ -717,7 +717,7 @@ A default ordering can be specified for your
717717:class: `~mongoengine.queryset.QuerySet ` is created, and can be overridden by
718718subsequent calls to :meth: `~mongoengine.queryset.QuerySet.order_by `. ::
719719
720- from datetime import datetime
720+ from datetime import datetime,timezone
721721
722722 class BlogPost(Document):
723723 title = StringField()
@@ -812,7 +812,7 @@ the class name in every documents. When a document is loaded, MongoEngine checks
812812it's :attr: `_cls ` attribute and use that class to construct the instance.::
813813
814814 Page(title='a funky title').save()
815- DatedPage(title='another title', date=datetime.utcnow( )).save()
815+ DatedPage(title='another title', date=datetime.now(timezone.utc )).save()
816816
817817 print(Page.objects().count()) # 2
818818 print(DatedPage.objects().count()) # 1
@@ -823,7 +823,7 @@ it's :attr:`_cls` attribute and use that class to construct the instance.::
823823 print(list(qs))
824824 # [
825825 # {'_cls': u 'Page', 'title': 'a funky title'},
826- # {'_cls': u 'Page.DatedPage', 'title': u 'another title', 'date': datetime.datetime (2019, 12, 13, 20, 16, 59, 993000)}
826+ # {'_cls': u 'Page.DatedPage', 'title': u 'another title', 'date': datetime(2019, 12, 13, 20, 16, 59, 993000)}
827827 # ]
828828
829829Working with existing data
0 commit comments