F
F
Friend2017-01-26 04:52:24
Django
Friend, 2017-01-26 04:52:24

How to implement adding to friends?

from django.db import models
from django.contrib.auth.models import User


class Friend(models.Model):
    class Meta:
        db_table = 'Friend'
    user = models.ForeignKey(User)
    friend = models.ForeignKey(User, related_name="friends")
    date = models.DateTimeField(auto_now_add=True)

Thus, I implemented adding friends, perhaps in this case it will be more relevant to use ManyToManyField or is there a more productive code?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Kuts, 2017-01-26
@fox_12

Alternatively, something like this:

class User(models.Model):
      ...
     friends = models.ManyToManyField("self", blank=True)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question