Usually, something that has multiple versions could be in an autoincrement field as the primary key. Then, in a JSONB field with GIN index (since you're using PostgreSQL), you would have a dict of each version, like this:
{
"1": { # beginning of article 1
"versions": {
"1": {
"title": "Blah1",
"timestamp": 172903740.0002782,
"image": "http:test.de/test.jpg",
"alt": "Super text"
}, # end of version 1
"2": {
"title": "Blah1",
"timestamp": 1729375394.0002782,
"image": "http:test.de/test.jpg",
"alt": "Super text blah"
}, # end of version 2
"3": {
"title": "Blah2",
"timestamp": 17290826300.0002782,
"image": "http:test.de/test.jpg",
"alt": "Super text blah"
} # end of version 3
} # end of versions attribute/column
}, # end of article 1
"2": {
"versions": {
"1": {
"title": "Blah1",
"timestamp": 172903740.0002782,
"image": "http:test.de/test.jpg",
"alt": "Super text"
}, # end of version 1
"2": {
"title": "Blah1",
"timestamp": 172903740.0002782,
"image": "http:test.de/test.jpg",
"alt": "Super text blah"
} # end of version 2
} # end of article 2
} # end of queryset
So your primary key is a BigAutoField and your "versions" attribute/column is a JSONField. IF YOU ARE FILTERING BASED ON ARTICLE TITLE, make sure you put a GIN Index on that JSONField.
On Thu, Jan 30, 2020 at 10:38 AM wagner <wagnerexpositio@gmail.com> wrote:
Hello together,--i have the following problem. I need to save different versions of an article in a json object:{"1580388458.2877874": {"title": "Erster Artikel","text_block_with_image": [{"text": "Super Text der einen weiterhilft", "image": "http://test.de/test.jpg"}]},"1580388556.6462297": {"title": "Erster Artikel angepasst","text_block_with_image": [{"text": "Super neuer neuer Text der einen weiterhilft", "image": "http://test.de/test.jpg"}]}}I save this information in a JSONField().The numbers here are the current time in seconds.I want to do an article template where i show the latest version of the article (by current time seconds).How can i filter after the latest version?Articles.objects.filter( ?? )My second problem:How can i delete the oldest version (key), when i add a new entry?Thank you!
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f0624188-fd77-4c50-acbe-b0c841043554%40googlegroups.com.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAJVmkNkauta7BFtSvjWZk4T%3DX6-974b9SKzP7x-wu%3D5WJha86Q%40mail.gmail.com.
No comments:
Post a Comment