N
N
Nmm3332019-07-29 18:40:58
Database design
Nmm333, 2019-07-29 18:40:58

How to implement a dynamic list in the database model?

Good afternoon, I'm new to the backend and therefore, perhaps a stupid question. I want to create a training REST Api service in Django that would simply store information about the user.
The user in JSON can be represented like this:

{
   "citizen_id": 1,
   "town": "Москва",
   "street": "Льва Толстого",
   "building": "16к7стр5",
   "apartment": 7,
   "name": "Иванов Иван Иванович", 
   "birth_date": " 26.12.1986",
    "gender": "male",
   "relatives": [2,4] // id родственников
}

How, in this case, to create a database model in which relatives can be empty, or can have several id? With everything else, more or less figured out.
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yura Khlyan, 2019-07-29
@Nmm333

You need ManyToMany

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question