1👍
There is an easy way to do it but you’ll have to drop the uniqueness of the SlugField.
class Post(models.Model):
user = models.ForeignKey('auth.User')
slug = models.SlugField(unique=False)
subject = models.CharField(max_length=255)
body = models.TextField()
version = models.DateTimeField(auto_now_add=True, auto_now=True)
What you do in your view is simply pull the instances with the same slug and order them by date, the latest date will obviously be the current version.
Then in your template, you’ll use the id field as a get variable, the redirect url for a version should look like this:
http://someurl.com/this-unique-post?v=3
Where 3 is the id of that post’s version, then if you want to make, say the version with id=3 as the current version, you’ll just save/update it again!
Hope this helps!
0👍
There are django apps for that. for example: https://github.com/etianen/django-reversion
- [Answer]-HTML changes not reflected in django-cms
- [Answer]-Django: how do i request username in SessionWizardView?
- [Answer]-How to to retrieve the SQL type of the primary key of a related field mapped by Django's ORM
- [Answer]-Issues with UUID field in django admin
- [Answer]-Django 1.8 and how to change migration order for apps
Source:stackexchange.com