Django test command fail after changing models.py to a directory structure

24 views
Skip to first unread message

Gonzalo Amadio

unread,
Jan 11, 2019, 2:26:09 AM1/11/19
to Django users

This is in Django 2.0 , python 3.6.5

I have an app called posts, and I changed models.py to a folder structure, i.e., create a directory models and move the file models.py insid. Also config __ init__.py file, as explained next. The project runs ok, but my test suite fails.

In my settings, installed apps i have the app as:

'myproject.apps.posts.apps.PostsConfig'

My app config (posts/apps.py)

from django.apps import AppConfig
class PostsConfig(AppConfig):    
    name = 'posts'               
    verbose_name = 'posts'    

I have move posts/models.py to a directory structure. So I have

posts/models/models.py
posts/models/proxymodels.py
posts/models/__init__.py

inside models/__ init__.py I do import my models as explained in doc

from .models import Job
from .proxys import ActiveJob

The project works well, but when trying to run tests:

python manage.py test

I have this error:

RuntimeError: Model class tektank.apps.posts.models.models.Job doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

The model is a normal one, with fields, nothing extrange. The thing is that if I declare in the meta

class Meta:
    app_label = 'posts'

I got the following error:

RuntimeError: Conflicting 'job' models in application 'posts': <class 'posts.models.models.Job'> and <class 'tektank.apps.posts.models.models.Job'>.

Note: If I use pytest, I run the command:

pytest

It runs OK


Reply all
Reply to author
Forward
0 new messages