1👍
✅
Your Product
model needs to import the User
model and vice versa. As a result the imports got stuck in an infinite loop.
You can however use a string literal to specify to what model your ManyToManyField
is pointing. For example:
# no import of the models module where you define User
class Product(models.Model):
#here are information fields about Product
likes = models.ManyToManyField(
'app_name.User', related_name="product_likes", blank=True
)
# ⋮
Here app_name
is the name of the app where you defined the (custom) user model.
Since it is (likely) the user model, you here can use the AUTH_USER_MODEL
setting [Django-doc]:
# no import of the models module where you define User
from django.conf import settings
class Product(models.Model):
#here are information fields about Product
likes = models.ManyToManyField(
settings.AUTH_USER_MODEL, related_name="product_likes", blank=True
)
# ⋮
Source:stackexchange.com