Determining if a Version created an object

15 views
Skip to first unread message

Evan Borgstrom

unread,
Jan 11, 2011, 9:30:24 AM1/11/11
to Django Reversion Discussion
Hi,

I'm trying to determine if a Version represents an object that was
newly created or not.

I'm checking if the object was deleted by trying to access
version.object_version.object and catching DoesNotExist, but I'm not
sure how to check if it's a newly created object.

Any advice or pointers is appreciated.

Thanks,
-E

David Hall

unread,
Jan 11, 2011, 9:32:31 AM1/11/11
to django-r...@googlegroups.com
This is one of those areas where, at some point, reversion might undergo a backwards-incompatible change to make things a little bit easier.

The current way of detecting an object creation is to see if any version objects with an earlier datestamp exist for that model. The first Version object for a model is implicitly assumed to represent it's creation.

This might be changes to a creation/update/deletion flag at some point. Or maybe not. The jury is still out.

Dave.


--
You received this message because you are subscribed to the Google Groups "Django Reversion Discussion" group.
To post to this group, send an email to django-r...@googlegroups.com.
To unsubscribe from this group, send email to django-reversi...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-reversion?hl=en-GB.




--
Dave Hall
Etianen.com

Telephone: 07525 452381
Web: http://www.etianen.com

Evan Borgstrom

unread,
Jan 11, 2011, 10:44:46 AM1/11/11
to Django Reversion Discussion
Hi Dave,

On Jan 11, 9:32 am, David Hall <da...@etianen.com> wrote:
> The current way of detecting an object creation is to see if any version
> objects with an earlier datestamp exist for that model. The first Version
> object for a model is implicitly assumed to represent it's creation.

Here's what I came up with, where version is the current version
object I'm comparing against:

qs = Version.objects.filter(object_id=version.object_id,
content_type=version.content_type,
revision__date_created__lt=version.revision.date_created)
if qs.count() == 0:
created = True

Seems to work pretty good. Would you do this any differently?

Thanks!
-E

David Hall

unread,
Jan 11, 2011, 10:48:37 AM1/11/11
to django-r...@googlegroups.com
That's a reasonable approach. I realize this feels a bit clunky, so if you're one of the people who would like a creation/update/delete flag on version objects, please raise an issue on github and we can discuss it.

Dave.


Thanks!
-E

--
You received this message because you are subscribed to the Google Groups "Django Reversion Discussion" group.
To post to this group, send an email to django-r...@googlegroups.com.
To unsubscribe from this group, send email to django-reversi...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-reversion?hl=en-GB.

Reply all
Reply to author
Forward
0 new messages