how to use table from many to many relationship?

Hello, I have a project where I want to use the table from the many to many relationship, but I can’t.
here is the error i have in the console : ImportError: cannot import name ‘Motif_Document’ from ‘Motif.models’ (C:\Users\ugb\Desktop\TRF\Motif\models.py)

indeed I have three models: pattern, Document and Folder:

Model Document:
from turtle import mode

from django.db import models

Create your models here.

class Document(models.Model):

designation=models.CharField(max_length=50)

create_time=models.DateTimeField(auto_now_add=True)



def __str__(self):

    return self.designation

Model Pattern :
from tkinter import CASCADE

from turtle import mode

from django.db import models

from Document.models import Document

Create your models here.

class Motif(models.Model):

m_designation=models.CharField(max_length=50)

document=models.ManyToManyField(Document)

create_time=models.DateTimeField(auto_now_add=True)



def __str__(self):

    return self.m_designation

class Contenir (models.Model):

motif=models.ForeignKey(Motif, on_delete=models.CASCADE)  

document=models.ForeignKey(Document, on_delete=models.CASCADE)

def __str__(self):

     return self.motif

Model Folder :
from django.db import models

from Motif.models import Motif_Document

from Agence.models import Agence

Create your models here.

class Dossier(models.Model):

statut=(('Valider ','Valider en Agance'),

        ('Valider controle BEAC','Valider controle BEAC'),

        ('Rejeter Controleur BEAC','Rejeter Controleur BEAC')

        )

devise=(('Euro','EUR'),

        ('Dollar Americain', 'USD'),

        ('YEN','JPY'),  

        ('MAD','MAD')

        )

agence=models.ForeignKey(Agence,null=True,on_delete=models.SET_NULL)

raison_sociale=models.CharField(max_length=50)

Numero_de_Compte=models.CharField(max_length=50)

motif=models.ForeignKey(Motif_Document, null=True,on_delete=models.SET_NULL,)

devise=models.CharField(max_length=50,choices=devise,default='EUR')

cours=models.FloatField(default=650)

mt_devise=models.FloatField()

beneficiaire=models.CharField(max_length=50)

statut=models.CharField(max_length=50,choices=statut,default='Valider en Agance')

create_time=models.DateTimeField(auto_now_add=True)

First, a side note: When posting code here, enclose each block of code between lines of three backtick - ` characters. This means you’ll have a line of ```, then your code, then another line of ```. This forces the forum software to keep your code properly formatted, which is critical with Python.

I do not see where you’ve defined a Model named Motif_Document.

Hello,
thank you for your suggestion, in fact it comes from the many to many relationship.

That is a table that may exist, but that is not a model. Django only provides access to tables through the ORM to Models.

If you want direct access to the join table created for a ManyToMany relationship, you need to create that relationship with the through option and define the model for it.
However, if you’re not addition additional fields to that model, I’m not sure why you think you need to access that table directly. The ORM will handle all the common-cases for you.

In fact I want to be able to use it in the folder table. what I want eventually. it’s choosing a pattern in a folder and by choosing it, I list all the documents attached to it.

You don’t need direct access to that join table to do that. See the docs on ManyToMany relationships to see how it’s done.