Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 Jan. 25, 2011 07:42:16

a.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Versioned database content


Hello all,

My problem is as follows: I have content (for simplicity, lets say
articles), and some content related to that (authors for the example).
I would like to add the ability for users to create versions of the
content. The procedure from user perspective is as follows: they click
a button ("create new version") and supply some details about the
update.

Now, I would like to automatically generate dual tables for articles
and content which would be versioned. That is, when users click
"create new version" my software should insert the current data into
the dual tables so that it is possible to go back to each published
version.

The problem I am facing is this: I would like to create automatically
the dual tables. I haven't thought about the schema much, but I
probably don't need anything more than the base tables + an integer
column version. Is there any relatively easy way to create the dual
tables automatically? That is, is it possible to read the models I
have currently and create the dual table without me having to copy all
the definitions. For example, given the article model:

class Author(models.Model):
name = models.TextField()

class Article(models.Model):
id = models.AutoField()
text = models.TextField()
authors = models.ManyToManyField(Author)

I would like to create automatically (in runtime or just create the
models.py file automatically running a script) the dual models:

class AuthorDual(models.Model):
name = models.TextField()
version = models.PositiveIntegerField()

class ArticleDual(models.Model):
id = models.AutoField()
text = models.TextField()
authors = models.ManyToManyField(AuthorDual)
version = models.PositiveIntegerField()

Has anybody done anything similar? Any pointers where to look for
similar code? And is this doable in sane amount of time?

Thanks in advance,
- Anssi

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 Jan. 25, 2011 09:45:49

Jani T.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Versioned database content


You probably want to look at abstract models in Django. It's also known as
concrete inheritance in some ORMs

--

Jani Tiainen

On Tuesday 25 January 2011 09:42:08 akaariai wrote:
> Hello all,
>
> My problem is as follows: I have content (for simplicity, lets say
> articles), and some content related to that (authors for the example).
> I would like to add the ability for users to create versions of the
> content. The procedure from user perspective is as follows: they click
> a button ("create new version") and supply some details about the
> update.
>
> Now, I would like to automatically generate dual tables for articles
> and content which would be versioned. That is, when users click
> "create new version" my software should insert the current data into
> the dual tables so that it is possible to go back to each published
> version.
>
> The problem I am facing is this: I would like to create automatically
> the dual tables. I haven't thought about the schema much, but I
> probably don't need anything more than the base tables + an integer
> column version. Is there any relatively easy way to create the dual
> tables automatically? That is, is it possible to read the models I
> have currently and create the dual table without me having to copy all
> the definitions. For example, given the article model:
>
> class Author(models.Model):
> name = models.TextField()
>
> class Article(models.Model):
> id = models.AutoField()
> text = models.TextField()
> authors = models.ManyToManyField(Author)
>
> I would like to create automatically (in runtime or just create the
> models.py file automatically running a script) the dual models:
>
> class AuthorDual(models.Model):
> name = models.TextField()
> version = models.PositiveIntegerField()
>
> class ArticleDual(models.Model):
> id = models.AutoField()
> text = models.TextField()
> authors = models.ManyToManyField(AuthorDual)
> version = models.PositiveIntegerField()
>
> Has anybody done anything similar? Any pointers where to look for
> similar code? And is this doable in sane amount of time?
>
> Thanks in advance,
> - Anssi

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#3 Jan. 25, 2011 10:08:37

Juergen S.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Versioned database content


why do you want to create the dual tables, instead of only having one table
with a current tag that holds the old version and the current ones? and then
handle access to those via different managers?
have you also had a look at the available versioning apps?

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#4 Jan. 25, 2011 11:09:53

a.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Versioned database content


On Jan 25, 12:08 pm, Juergen Schackmann
<juergen.schackm...@googlemail.com> wrote:
> why do you want to create the dual tables, instead of only having one table
> with a current tag that holds the old version and the current ones? and then
> handle access to those via different managers?
> have you also had a look at the available versioning apps?

I forgot to include this in my original post: I already have a working
application and I would like to be able to add versioning support
without changing the current schema. Also, I am using Admin, and I am
afraid of the amount of work this would require. I am currently using
a setup where each change gets logged into dual tables using plpgsql
triggers, but as the content is relatively large per row, and updated
quite often, while new versions aren't that common, I will get a lot
of bloat in the dual tables using my current setup. And it is a bit
hard to actually fetch the correct version from the dual tables...

I will look into the existing versioning apps, maybe one of the will
allow me to easily create this kind of setup.

Thank you for the help,
- Anssi

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#5 Jan. 25, 2011 13:33:23

Juergen S.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Versioned database content


see herehttp://djangopackages.com/grids/g/versioning/ore there is also a interesting chapter on versioning on page 263 here:http://books.google.com/books?id=lJwOcsZq5g4C&printsec=frontcover&dq=django+pro&hl=de&ei=TdA-TdSyH4GA4Aat1fGwCg&sa=X&oi=book_result&ct=book-thumbnail&resnum=1&ved=0CCwQ6wEwAA#v=onepage&q&f=falseplease share your results

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

Board footer

Moderator control

Enjoy the 23rd of October
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support