Y
Y
Yura2021-03-24 13:45:40
Django
Yura, 2021-03-24 13:45:40

How to link 2 fields?

I can’t figure it out, I have a Chat and Message model, what connection should I use in this case and how can I add an object of the Message class there, I thought to just make a list, without a connection and add it there, but it is not entered into the database.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Kuts, 2021-03-24
@N0tdefined

What exactly are the difficulties?
Something like this - and forward:

class Chat(models.Model):
     ...

class Message(models.Model):
     chat = models.ForeignKey(Chat, on_delete=models.CASCADE)
     ...

D
Dr. Bacon, 2021-03-24
@bacon

Message should have chat = models.ForeignKey(Chat), but it's better to first learn the basics of relational databases, and then write something in django/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question