Hello I’m spliting my files because the model is getting bigger. So here we are again with problems:
My models;
If in my Category model I remove the “ArticleToCategory” and the many-to-many relationship it works well. But I need them!
How to fix it?
I deleted the model.py in order to load files from the model package.
Category (models.category):
class Category(MPTTModel):
# relationships
from RubeteDjango01.generic.models.article import Article
from RubeteDjango01.generic.models.article_to_category import ArticleToCategory
articles = m.ManyToManyField(Article, through=ArticleToCategory)
ArticleToCategory (models.article_to_category):
from django.db import models as m
class ArticleToCategory(m.Model):
from RubeteDjango01.generic.models.article import Article
from RubeteDjango01.generic.models.category import Category
article = m.ForeignKey(Article)
category = m.ForeignKey(Category)
class Meta:
db_table = 'articles_to_categories'
verbose_name_plural = 'ArticlesToCategories'
thanks
You can define foreign keys using strings, to avoid exactly this problem.