0

I am using Django default User model. I've made a relation m2m to it with model Books. Django made automaticly table in library app - library_books_user. How can I get acces to it? I want to be able to delete relations.

Normally when I use not built in models i can do it like: models.BooksUsers.objects.get(book=book, user=user) importing models before.

Jumper
  • 1
  • 1

1 Answers1

0

You need the instance of book and user then you can delete the user relation from the Book model like this.

user = User.objects.get(pk=pk)
book = Book.objects.get(pk=pk)

book.users.remove(user)

Ex: Django removing object from ManyToMany relationship

ShiBil PK
  • 588
  • 3
  • 13