I
I
Igor2022-01-29 12:06:56
Django
Igor, 2022-01-29 12:06:56

How to create a table in which information about the post will be stored?

There is a table in the database with the primary key already created, the title of the post, and so on.
I want to separately display in the database in another table the number of likes and dislikes for each post.
It is necessary that in the new table rows be created according to the already existing primary key from the existing one.
What relation to use when creating a model?
What parameter to specify so that lines would be created for all existing posts?
Google doesn't give the information I'm looking for.
I would be grateful for any help!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
FanatPHP, 2022-01-29
@karonion

Google is doing exactly the right thing. Because doing such rubbish is easy for no one to come up with.
Firstly, a separate table is not needed here, it's just two columns in the same table
. Secondly, if you make a separate table, then empty rows are never created in the database in reserve . The database is not a paper diary with deuces, lined for a whole year. It is structured differently.

A
alexalexes, 2022-01-29
@alexalexes

If you just want to count how many likes and dislikes a post has, then just enter two new columns in the posts table.
If you want to log likes and dislikes and then analyze how many likes and dislikes were posted per hour, day, week, month, then create a separate table for likes:
Table LIKES
id_like,
id_post,
id_like_type, -- like/dislike
date_time_of placement
But even logging likes, you can keep track of their quantity in separate columns of the post - one does not interfere with the other.
The relational model will not be able to offer other optimal solutions for your task.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question