{"action":"created","issue":{"url":"https://api.github.com/repos/etianen/django-reversion/issues/721","repository_url":"https://api.github.com/repos/etianen/django-reversion","labels_url":"https://api.github.com/repos/etianen/django-reversion/issues/721/labels{/name}","comments_url":"https://api.github.com/repos/etianen/django-reversion/issues/721/comments","events_url":"https://api.github.com/repos/etianen/django-reversion/issues/721/events","html_url":"https://github.com/etianen/django-reversion/issues/721","id":320089367,"node_id":"MDU6SXNzdWUzMjAwODkzNjc=","number":721,"title":"DateTimeField handling is broken with django-reversion with AttributeError: 'unicode' object has no attribute 'isoformat'","user":{"login":"oliver-zhou","id":906828,"node_id":"MDQ6VXNlcjkwNjgyOA==","avatar_url":"https://avatars3.githubusercontent.com/u/906828?v=4","gravatar_id":"","url":"https://api.github.com/users/oliver-zhou","html_url":"https://github.com/oliver-zhou","followers_url":"https://api.github.com/users/oliver-zhou/followers","following_url":"https://api.github.com/users/oliver-zhou/following{/other_user}","gists_url":"https://api.github.com/users/oliver-zhou/gists{/gist_id}","starred_url":"https://api.github.com/users/oliver-zhou/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/oliver-zhou/subscriptions","organizations_url":"https://api.github.com/users/oliver-zhou/orgs","repos_url":"https://api.github.com/users/oliver-zhou/repos","events_url":"https://api.github.com/users/oliver-zhou/events{/privacy}","received_events_url":"https://api.github.com/users/oliver-zhou/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-05-03T21:38:33Z","updated_at":"2018-07-19T17:42:54Z","closed_at":"2018-07-19T09:24:43Z","author_association":"NONE","body":"I'm having issues using the Django Admin + Django Reversion with DateTimeField values. This is somewhat similar to #632 \r\n\r\nWhen manually saving a string value like this : '2017-08-08T22:51:15.125Z' to the DateTimeField of a value, it works fine from shell, but it does not work in the Django Admin.\r\n\r\nExample in shell or Django code outside of admin\r\n```\r\nobj.date_created = '2017-08-16T22:51:15.125Z'\r\nobj.save()\r\nobj.refresh_from_db()\r\nobj.date_created\r\n\r\n```\r\nResult is something like this is saved into the object\r\n`datetime.datetime(2017, 8, 16, 22, 51, 15, 125000, tzinfo=<UTC>)\r\n`\r\nThe model has an overridden save function, somewhat like this -\r\n\r\n```\r\n    def save(self, *args, **kwargs):\r\n        self.date_created = '2017-08-16T22:51:15.125Z'\r\n        super(Obj, self).save(*args, **kwargs)\r\n```\r\n\r\nHowever, when using the Django admin to save a change to this object that then tries to save that same string value down, everything blows up, and I get an\r\nAttributeError: 'unicode' object has no attribute 'isoformat'\r\n\r\nThis only happens during the add_to_revision portion of django-reversion from django admin, and nowhere else.\r\n\r\ndjango-reversion==2.0.13\r\nDjango==1.11.13 and Django==1.11.12\r\npython 2.7.10\r\n\r\nReproducible Model - \r\n\r\n```\r\nclass TestCase(models.Model):\r\n    date_created = models.DateTimeField(\r\n        null=True, blank=True, auto_now_add=True)\r\n\r\n    def save(self, *args, **kwargs):\r\n        self.date_created = '2017-08-16T22:51:15.125Z'\r\n        super(TestCase, self).save(*args, **kwargs)\r\n\r\n```\r\nIn admin.py - \r\n\r\n```\r\nclass TestCaseResource(resources.ModelResource):\r\n    '''To set up RecruiterResource'''\r\n    class Meta:\r\n        model = Recruiter\r\n\r\nclass TestCaseAdmin(VersionAdmin, OrganizationAdmin):\r\n    '''RecruiterOrganization Admin.\r\n\r\n    Trying to subclass the official django-organization admin\r\n    '''\r\n    resource_class = RecruiterOrganizationResource\r\n```\r\n\r\nPartial Trace \r\n```\r\n\r\n  File \"/Users/oliver/.virtualenvs/hirevisor_api/lib/python2.7/site-packages/django/contrib/admin/options.py\", line 1408, in changeform_view\r\n    return self._changeform_view(request, object_id, form_url, extra_context)\r\n  File \"/Users/oliver/.virtualenvs/hirevisor_api/lib/python2.7/site-packages/django/contrib/admin/options.py\", line 1448, in _changeform_view\r\n    self.save_model(request, new_object, form, not add)\r\n  File \"/Users/oliver/.virtualenvs/hirevisor_api/lib/python2.7/site-packages/django/contrib/admin/options.py\", line 979, in save_model\r\n    obj.save()\r\n  File \"/Users/oliver/src/h_mvp_backend/recruiters/models.py\", line 239, in save\r\n    super(TestCase, self).save(*args, **kwargs)\r\n  File \"/Users/oliver/.virtualenvs/hirevisor_api/lib/python2.7/site-packages/django/db/models/base.py\", line 808, in save\r\n    force_update=force_update, update_fields=update_fields)\r\n  File \"/Users/oliver/.virtualenvs/hirevisor_api/lib/python2.7/site-packages/django/db/models/base.py\", line 848, in save_base\r\n    update_fields=update_fields, raw=raw, using=using,\r\n  File \"/Users/oliver/.virtualenvs/hirevisor_api/lib/python2.7/site-packages/django/dispatch/dispatcher.py\", line 193, in send\r\n    for receiver in self._live_receivers(sender)\r\n  File \"/Users/oliver/.virtualenvs/hirevisor_api/lib/python2.7/site-packages/reversion/revisions.py\", line 329, in _post_save_receiver\r\n    add_to_revision(instance, model_db=using)\r\n  File \"/Users/oliver/.virtualenvs/hirevisor_api/lib/python2.7/site-packages/reversion/revisions.py\", line 215, in add_to_revision\r\n    _add_to_revision(obj, db, model_db, True)\r\n  File \"/Users/oliver/.virtualenvs/hirevisor_api/lib/python2.7/site-packages/reversion/revisions.py\", line 194, in _add_to_revision\r\n    fields=version_options.fields,\r\n  File \"/Users/oliver/.virtualenvs/hirevisor_api/lib/python2.7/site-packages/django/core/serializers/__init__.py\", line 129, in serialize\r\n    s.serialize(queryset, **options)\r\n  File \"/Users/oliver/.virtualenvs/hirevisor_api/lib/python2.7/site-packages/django/core/serializers/base.py\", line 89, in serialize\r\n    self.handle_field(obj, field)\r\n  File \"/Users/oliver/.virtualenvs/hirevisor_api/lib/python2.7/site-packages/django/core/serializers/python.py\", line 54, in handle_field\r\n    self._current[field.name] = field.value_to_string(obj)\r\n  File \"/Users/oliver/.virtualenvs/hirevisor_api/lib/python2.7/site-packages/django/db/models/fields/__init__.py\", line 1464, in value_to_string\r\n    return '' if val is None else val.isoformat()\r\nAttributeError: 'unicode' object has no attribute 'isoformat'\r\n```"},"comment":{"url":"https://api.github.com/repos/etianen/django-reversion/issues/comments/406358437","html_url":"https://github.com/etianen/django-reversion/issues/721#issuecomment-406358437","issue_url":"https://api.github.com/repos/etianen/django-reversion/issues/721","id":406358437,"node_id":"MDEyOklzc3VlQ29tbWVudDQwNjM1ODQzNw==","user":{"login":"oliver-zhou","id":906828,"node_id":"MDQ6VXNlcjkwNjgyOA==","avatar_url":"https://avatars3.githubusercontent.com/u/906828?v=4","gravatar_id":"","url":"https://api.github.com/users/oliver-zhou","html_url":"https://github.com/oliver-zhou","followers_url":"https://api.github.com/users/oliver-zhou/followers","following_url":"https://api.github.com/users/oliver-zhou/following{/other_user}","gists_url":"https://api.github.com/users/oliver-zhou/gists{/gist_id}","starred_url":"https://api.github.com/users/oliver-zhou/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/oliver-zhou/subscriptions","organizations_url":"https://api.github.com/users/oliver-zhou/orgs","repos_url":"https://api.github.com/users/oliver-zhou/repos","events_url":"https://api.github.com/users/oliver-zhou/events{/privacy}","received_events_url":"https://api.github.com/users/oliver-zhou/received_events","type":"User","site_admin":false},"created_at":"2018-07-19T17:42:54Z","updated_at":"2018-07-19T17:42:54Z","author_association":"NONE","body":"@etianen - but if a field is capable of handling specific types of input and converting it internally - shouldn't revision be able to handle that as well? i.e., cases like this - where it works fine since datetime can convert strings to datetime objects, one operating on this belief would be broken by django-reversion "}}
{"actor":{"display_login":"oliver-zhou"}}