Thank you both for your replies.
My code is using the correct database.
The models for the home page and about pages are identical:
class HomePage(models.Model):
node = models.OneToOneField(Node, on_delete=models.CASCADE, primary_key=True, related_name=‘home_pages’, related_query_name=‘home_page’)
content = models.TextField()
class AboutWhoPage(models.Model):
node = models.OneToOneField(Node, on_delete=models.CASCADE, primary_key=True, related_name=‘about_who_pages’, related_query_name=‘about_who_page’)
content = models.TextField()
…
When there is no data in the database and I request the HomePageEditView(UpdateView), the node_id, object and created attributes have these values:
node id abf2ff22-c4d2-4e59-aba5-f64ff7b3665e
object
created True
[11/Jul/2022 09:39:41] “GET /pages/homepage/ HTTP/1.1” 200 4112
When I enter a value for content and submit the form the attributes have these values:
node id abf2ff22-c4d2-4e59-aba5-f64ff7b3665e
object
created False
[11/Jul/2022 09:44:49] “POST /pages/homepage/ HTTP/1.1” 302 0
When I request the HomePageEditView(UpdateView) again, the attributes have these values:
node id abf2ff22-c4d2-4e59-aba5-f64ff7b3665e
object This is the home page content
created False
[11/Jul/2022 09:51:34] “GET /pages/homepage/ HTTP/1.1” 200 4280
When I want to edit the content for the ‘about who’ page and I request the AboutWhoPageEditView(UpdateView) this is the output:
node id: abf2ff22-c4d2-4e59-aba5-f64ff7b3665e
object:
created: False
[11/Jul/2022 09:54:26] “GET /pages/aboutwhopage/ HTTP/1.1” 200 4255
Although the AboutWhoPage table is empty the value of the created attributes is False, where I expect it to be True.
It’s as if the get_or_create() is ignoring the fact that I query a different table for node_id=self.request.user.node_id each time.
The following the output for adding content to an empty AboutWhoPage table:
object:
created: False
[11/Jul/2022 09:54:26] “GET /pages/aboutwhopage/ HTTP/1.1” 200 4255
node id: abf2ff22-c4d2-4e59-aba5-f64ff7b3665e
object:
created: False
[11/Jul/2022 10:02:03] “POST /pages/aboutwhopage/ HTTP/1.1” 302 0
[11/Jul/2022 10:02:03] “GET /pages/ HTTP/1.1” 200 5353
node id: abf2ff22-c4d2-4e59-aba5-f64ff7b3665e
object: This is the about who page conte
created: False
[11/Jul/2022 10:02:15] “GET /pages/aboutwhopage/ HTTP/1.1” 200 4289
As you can see it’s only the created attribute that doesn’t have the correct value.
Kind regards,
Johanna