Django dumpdata returns empty array when models are in a version subdirectory
I have a Django Rest Framework app where I have separated my models/serializers/views into separate directories (instead of in models.py, serializers.py, etc) and moved those directories into a v1 directory.
When I try to run ./manage.py dumpdata api I get an empty array as response.
./manage.py dumpdata will dump out the Django system tables, but none of my model tables.
Here's an example:
- api/
-- __init__.py
-- v1/
--- router.py
--- __init__.py
--- models/
---- __init__.py
---- thingy.py
--- serializers/
---- __init__.py
---- thingy.py
--- views/
---- __init__.py
---- thingy.py
- project/
-- urls.py
-- settings.py
-- wsgi.py
-- __init__.py
The __init__.py file inside each object directory (e.g. models) includes the class from each file:
from .thingy import Thingy
The router.py file inside api/ looks like this:
from rest_framework import routers
from . import views
router = routers.DefaultRouter(trailing_slash=False)
router.register(r'thingies', views.ThingyViewSet)
api_urlpatterns = router.urls
And urls.py inside project/ looks like this:
from django.conf.urls import url, include
from django.contrib import admin
from django.urls import path
from api.v1.router import api_urlpatterns as api_v1
urlpatterns = [
path('admin/', admin.site.urls),
url(r'^api/v1/', include(api_v1)),
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
]
python django django-rest-framework
add a comment |
I have a Django Rest Framework app where I have separated my models/serializers/views into separate directories (instead of in models.py, serializers.py, etc) and moved those directories into a v1 directory.
When I try to run ./manage.py dumpdata api I get an empty array as response.
./manage.py dumpdata will dump out the Django system tables, but none of my model tables.
Here's an example:
- api/
-- __init__.py
-- v1/
--- router.py
--- __init__.py
--- models/
---- __init__.py
---- thingy.py
--- serializers/
---- __init__.py
---- thingy.py
--- views/
---- __init__.py
---- thingy.py
- project/
-- urls.py
-- settings.py
-- wsgi.py
-- __init__.py
The __init__.py file inside each object directory (e.g. models) includes the class from each file:
from .thingy import Thingy
The router.py file inside api/ looks like this:
from rest_framework import routers
from . import views
router = routers.DefaultRouter(trailing_slash=False)
router.register(r'thingies', views.ThingyViewSet)
api_urlpatterns = router.urls
And urls.py inside project/ looks like this:
from django.conf.urls import url, include
from django.contrib import admin
from django.urls import path
from api.v1.router import api_urlpatterns as api_v1
urlpatterns = [
path('admin/', admin.site.urls),
url(r'^api/v1/', include(api_v1)),
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
]
python django django-rest-framework
Do you have your application in INSTALLED_APPS?
– vishes_shell
Nov 20 at 18:06
I do, as "api". In api/apps.py, I have thenameattribute of my ApiConfig as "api" as well.
– Jim Rohrer
Nov 20 at 20:22
add a comment |
I have a Django Rest Framework app where I have separated my models/serializers/views into separate directories (instead of in models.py, serializers.py, etc) and moved those directories into a v1 directory.
When I try to run ./manage.py dumpdata api I get an empty array as response.
./manage.py dumpdata will dump out the Django system tables, but none of my model tables.
Here's an example:
- api/
-- __init__.py
-- v1/
--- router.py
--- __init__.py
--- models/
---- __init__.py
---- thingy.py
--- serializers/
---- __init__.py
---- thingy.py
--- views/
---- __init__.py
---- thingy.py
- project/
-- urls.py
-- settings.py
-- wsgi.py
-- __init__.py
The __init__.py file inside each object directory (e.g. models) includes the class from each file:
from .thingy import Thingy
The router.py file inside api/ looks like this:
from rest_framework import routers
from . import views
router = routers.DefaultRouter(trailing_slash=False)
router.register(r'thingies', views.ThingyViewSet)
api_urlpatterns = router.urls
And urls.py inside project/ looks like this:
from django.conf.urls import url, include
from django.contrib import admin
from django.urls import path
from api.v1.router import api_urlpatterns as api_v1
urlpatterns = [
path('admin/', admin.site.urls),
url(r'^api/v1/', include(api_v1)),
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
]
python django django-rest-framework
I have a Django Rest Framework app where I have separated my models/serializers/views into separate directories (instead of in models.py, serializers.py, etc) and moved those directories into a v1 directory.
When I try to run ./manage.py dumpdata api I get an empty array as response.
./manage.py dumpdata will dump out the Django system tables, but none of my model tables.
Here's an example:
- api/
-- __init__.py
-- v1/
--- router.py
--- __init__.py
--- models/
---- __init__.py
---- thingy.py
--- serializers/
---- __init__.py
---- thingy.py
--- views/
---- __init__.py
---- thingy.py
- project/
-- urls.py
-- settings.py
-- wsgi.py
-- __init__.py
The __init__.py file inside each object directory (e.g. models) includes the class from each file:
from .thingy import Thingy
The router.py file inside api/ looks like this:
from rest_framework import routers
from . import views
router = routers.DefaultRouter(trailing_slash=False)
router.register(r'thingies', views.ThingyViewSet)
api_urlpatterns = router.urls
And urls.py inside project/ looks like this:
from django.conf.urls import url, include
from django.contrib import admin
from django.urls import path
from api.v1.router import api_urlpatterns as api_v1
urlpatterns = [
path('admin/', admin.site.urls),
url(r'^api/v1/', include(api_v1)),
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
]
python django django-rest-framework
python django django-rest-framework
asked Nov 20 at 17:44
Jim Rohrer
11
11
Do you have your application in INSTALLED_APPS?
– vishes_shell
Nov 20 at 18:06
I do, as "api". In api/apps.py, I have thenameattribute of my ApiConfig as "api" as well.
– Jim Rohrer
Nov 20 at 20:22
add a comment |
Do you have your application in INSTALLED_APPS?
– vishes_shell
Nov 20 at 18:06
I do, as "api". In api/apps.py, I have thenameattribute of my ApiConfig as "api" as well.
– Jim Rohrer
Nov 20 at 20:22
Do you have your application in INSTALLED_APPS?
– vishes_shell
Nov 20 at 18:06
Do you have your application in INSTALLED_APPS?
– vishes_shell
Nov 20 at 18:06
I do, as "api". In api/apps.py, I have the
name attribute of my ApiConfig as "api" as well.– Jim Rohrer
Nov 20 at 20:22
I do, as "api". In api/apps.py, I have the
name attribute of my ApiConfig as "api" as well.– Jim Rohrer
Nov 20 at 20:22
add a comment |
1 Answer
1
active
oldest
votes
I think I figured out the issue. While I had the files in each v1 folder (models, serializers, views) included in their respective __init__.py files, the manager was still expecting a models module in the base of the api directory. I added a models.py file and included each of the models under api.v1.models and now it appears to be finding my models.
Thanks for looking!
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53398653%2fdjango-dumpdata-returns-empty-array-when-models-are-in-a-version-subdirectory%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I think I figured out the issue. While I had the files in each v1 folder (models, serializers, views) included in their respective __init__.py files, the manager was still expecting a models module in the base of the api directory. I added a models.py file and included each of the models under api.v1.models and now it appears to be finding my models.
Thanks for looking!
add a comment |
I think I figured out the issue. While I had the files in each v1 folder (models, serializers, views) included in their respective __init__.py files, the manager was still expecting a models module in the base of the api directory. I added a models.py file and included each of the models under api.v1.models and now it appears to be finding my models.
Thanks for looking!
add a comment |
I think I figured out the issue. While I had the files in each v1 folder (models, serializers, views) included in their respective __init__.py files, the manager was still expecting a models module in the base of the api directory. I added a models.py file and included each of the models under api.v1.models and now it appears to be finding my models.
Thanks for looking!
I think I figured out the issue. While I had the files in each v1 folder (models, serializers, views) included in their respective __init__.py files, the manager was still expecting a models module in the base of the api directory. I added a models.py file and included each of the models under api.v1.models and now it appears to be finding my models.
Thanks for looking!
answered Nov 20 at 21:03
Jim Rohrer
11
11
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53398653%2fdjango-dumpdata-returns-empty-array-when-models-are-in-a-version-subdirectory%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Do you have your application in INSTALLED_APPS?
– vishes_shell
Nov 20 at 18:06
I do, as "api". In api/apps.py, I have the
nameattribute of my ApiConfig as "api" as well.– Jim Rohrer
Nov 20 at 20:22