Django Rest Framework url filter, import views error
I'm currently having trouble with writing Django Rest Framework filtering data by url. For some reason the problem seems to be when I import my views. The error points to the models which was working fine before I added the url filter in urls.py
File "/home/jd_dhang/drf-demo/project/urls.py", line 5, in <module>
from apps.core.views import SurgeryView
File "/home/jd_dhang/drf-demo/project/apps/core/views.py", line 2, in <module>
from .models import University, Student, SurgeryType
File "/home/jd_dhang/drf-demo/project/apps/core/models.py", line 3, in <module>
class University(models.Model):
File "/home/jd_dhang/drf-demo/venv/lib/python3.5/site-packages/django/db/models/base.py", line 102, in __new__
"INSTALLED_APPS." % (module, name)
RuntimeError: Model class apps.core.models.University doesn't declare an explicit app_label and isn't in an applica
tion in INSTALLED_APPS.
Django==1.9.13, djangorestframework==3.6.0
project/urls.py
**from apps.core.views import SurgeryView**
urlpatterns = [
**url(r'^api/surgery/(?P<surgery_type>.+)/$', SurgeryView.as_view())**,
...
]
project/apps/core/views.py
from rest_framework import viewsets
from .models import University, Student, SurgeryType
from .serializers import UniversitySerializer, StudentSerializer, SurgeryTypeSerializer
class StudentViewSet(viewsets.ModelViewSet):
...
class UniversityViewSet(viewsets.ModelViewSet):
...
class SurgeryView(viewsets.ModelViewSet): #(APIView):
queryset = SurgeryType.objects.all()
serializer_class = SurgeryTypeSerializer
def get_queryset(self):
queryset = SurgeryType.objects.all()
surgery_type = self.kwargs['surgery_type']
return SurgeryType.objects.filter(surgery_type=surgery_type)
Here are my models if it helps
project/apps/core/models.py
from django.db import models
class University(models.Model):
name = models.CharField(max_length=50)
class Meta:
verbose_name = "University"
verbose_name_plural = "Universities"
def __str__(self):
return self.name
class Student(models.Model):
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
university = models.ForeignKey(University)
class Meta:
verbose_name = "Student"
verbose_name_plural = "Students"
def __str__(self):
return '%s %s' % (self.first_name, self.last_name)
class SurgeryType(models.Model):
surgery_type = models.CharField("surgery_type", max_length=200)
sub_type = models.IntegerField(default=1)
available = models.BooleanField()
url = models.URLField(max_length=200, default='https://www.google.com')
def __str__(self):
return 'Type: ' + self.surgery_type + ' SubType : ' + str(self.sub_type)
Thank you
project/conf/base.py
ALLOWED_HOSTS = ['*']
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'core',
'rest_framework',
'rest_framework_swagger'
]
python django django-rest-framework django-views
add a comment |
I'm currently having trouble with writing Django Rest Framework filtering data by url. For some reason the problem seems to be when I import my views. The error points to the models which was working fine before I added the url filter in urls.py
File "/home/jd_dhang/drf-demo/project/urls.py", line 5, in <module>
from apps.core.views import SurgeryView
File "/home/jd_dhang/drf-demo/project/apps/core/views.py", line 2, in <module>
from .models import University, Student, SurgeryType
File "/home/jd_dhang/drf-demo/project/apps/core/models.py", line 3, in <module>
class University(models.Model):
File "/home/jd_dhang/drf-demo/venv/lib/python3.5/site-packages/django/db/models/base.py", line 102, in __new__
"INSTALLED_APPS." % (module, name)
RuntimeError: Model class apps.core.models.University doesn't declare an explicit app_label and isn't in an applica
tion in INSTALLED_APPS.
Django==1.9.13, djangorestframework==3.6.0
project/urls.py
**from apps.core.views import SurgeryView**
urlpatterns = [
**url(r'^api/surgery/(?P<surgery_type>.+)/$', SurgeryView.as_view())**,
...
]
project/apps/core/views.py
from rest_framework import viewsets
from .models import University, Student, SurgeryType
from .serializers import UniversitySerializer, StudentSerializer, SurgeryTypeSerializer
class StudentViewSet(viewsets.ModelViewSet):
...
class UniversityViewSet(viewsets.ModelViewSet):
...
class SurgeryView(viewsets.ModelViewSet): #(APIView):
queryset = SurgeryType.objects.all()
serializer_class = SurgeryTypeSerializer
def get_queryset(self):
queryset = SurgeryType.objects.all()
surgery_type = self.kwargs['surgery_type']
return SurgeryType.objects.filter(surgery_type=surgery_type)
Here are my models if it helps
project/apps/core/models.py
from django.db import models
class University(models.Model):
name = models.CharField(max_length=50)
class Meta:
verbose_name = "University"
verbose_name_plural = "Universities"
def __str__(self):
return self.name
class Student(models.Model):
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
university = models.ForeignKey(University)
class Meta:
verbose_name = "Student"
verbose_name_plural = "Students"
def __str__(self):
return '%s %s' % (self.first_name, self.last_name)
class SurgeryType(models.Model):
surgery_type = models.CharField("surgery_type", max_length=200)
sub_type = models.IntegerField(default=1)
available = models.BooleanField()
url = models.URLField(max_length=200, default='https://www.google.com')
def __str__(self):
return 'Type: ' + self.surgery_type + ' SubType : ' + str(self.sub_type)
Thank you
project/conf/base.py
ALLOWED_HOSTS = ['*']
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'core',
'rest_framework',
'rest_framework_swagger'
]
python django django-rest-framework django-views
2
Is your app is included in theINSTALLED_APPS?
– Abdul Niyas P M
Nov 16 '18 at 11:04
1
Please add yourINSTALLED_APPSfrom settings file in question
– Mohammad Umair
Nov 16 '18 at 12:08
Hi, I've added my INSTALLED_APPS
– Jade Dhangwattanotai
Nov 16 '18 at 12:39
add a comment |
I'm currently having trouble with writing Django Rest Framework filtering data by url. For some reason the problem seems to be when I import my views. The error points to the models which was working fine before I added the url filter in urls.py
File "/home/jd_dhang/drf-demo/project/urls.py", line 5, in <module>
from apps.core.views import SurgeryView
File "/home/jd_dhang/drf-demo/project/apps/core/views.py", line 2, in <module>
from .models import University, Student, SurgeryType
File "/home/jd_dhang/drf-demo/project/apps/core/models.py", line 3, in <module>
class University(models.Model):
File "/home/jd_dhang/drf-demo/venv/lib/python3.5/site-packages/django/db/models/base.py", line 102, in __new__
"INSTALLED_APPS." % (module, name)
RuntimeError: Model class apps.core.models.University doesn't declare an explicit app_label and isn't in an applica
tion in INSTALLED_APPS.
Django==1.9.13, djangorestframework==3.6.0
project/urls.py
**from apps.core.views import SurgeryView**
urlpatterns = [
**url(r'^api/surgery/(?P<surgery_type>.+)/$', SurgeryView.as_view())**,
...
]
project/apps/core/views.py
from rest_framework import viewsets
from .models import University, Student, SurgeryType
from .serializers import UniversitySerializer, StudentSerializer, SurgeryTypeSerializer
class StudentViewSet(viewsets.ModelViewSet):
...
class UniversityViewSet(viewsets.ModelViewSet):
...
class SurgeryView(viewsets.ModelViewSet): #(APIView):
queryset = SurgeryType.objects.all()
serializer_class = SurgeryTypeSerializer
def get_queryset(self):
queryset = SurgeryType.objects.all()
surgery_type = self.kwargs['surgery_type']
return SurgeryType.objects.filter(surgery_type=surgery_type)
Here are my models if it helps
project/apps/core/models.py
from django.db import models
class University(models.Model):
name = models.CharField(max_length=50)
class Meta:
verbose_name = "University"
verbose_name_plural = "Universities"
def __str__(self):
return self.name
class Student(models.Model):
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
university = models.ForeignKey(University)
class Meta:
verbose_name = "Student"
verbose_name_plural = "Students"
def __str__(self):
return '%s %s' % (self.first_name, self.last_name)
class SurgeryType(models.Model):
surgery_type = models.CharField("surgery_type", max_length=200)
sub_type = models.IntegerField(default=1)
available = models.BooleanField()
url = models.URLField(max_length=200, default='https://www.google.com')
def __str__(self):
return 'Type: ' + self.surgery_type + ' SubType : ' + str(self.sub_type)
Thank you
project/conf/base.py
ALLOWED_HOSTS = ['*']
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'core',
'rest_framework',
'rest_framework_swagger'
]
python django django-rest-framework django-views
I'm currently having trouble with writing Django Rest Framework filtering data by url. For some reason the problem seems to be when I import my views. The error points to the models which was working fine before I added the url filter in urls.py
File "/home/jd_dhang/drf-demo/project/urls.py", line 5, in <module>
from apps.core.views import SurgeryView
File "/home/jd_dhang/drf-demo/project/apps/core/views.py", line 2, in <module>
from .models import University, Student, SurgeryType
File "/home/jd_dhang/drf-demo/project/apps/core/models.py", line 3, in <module>
class University(models.Model):
File "/home/jd_dhang/drf-demo/venv/lib/python3.5/site-packages/django/db/models/base.py", line 102, in __new__
"INSTALLED_APPS." % (module, name)
RuntimeError: Model class apps.core.models.University doesn't declare an explicit app_label and isn't in an applica
tion in INSTALLED_APPS.
Django==1.9.13, djangorestframework==3.6.0
project/urls.py
**from apps.core.views import SurgeryView**
urlpatterns = [
**url(r'^api/surgery/(?P<surgery_type>.+)/$', SurgeryView.as_view())**,
...
]
project/apps/core/views.py
from rest_framework import viewsets
from .models import University, Student, SurgeryType
from .serializers import UniversitySerializer, StudentSerializer, SurgeryTypeSerializer
class StudentViewSet(viewsets.ModelViewSet):
...
class UniversityViewSet(viewsets.ModelViewSet):
...
class SurgeryView(viewsets.ModelViewSet): #(APIView):
queryset = SurgeryType.objects.all()
serializer_class = SurgeryTypeSerializer
def get_queryset(self):
queryset = SurgeryType.objects.all()
surgery_type = self.kwargs['surgery_type']
return SurgeryType.objects.filter(surgery_type=surgery_type)
Here are my models if it helps
project/apps/core/models.py
from django.db import models
class University(models.Model):
name = models.CharField(max_length=50)
class Meta:
verbose_name = "University"
verbose_name_plural = "Universities"
def __str__(self):
return self.name
class Student(models.Model):
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
university = models.ForeignKey(University)
class Meta:
verbose_name = "Student"
verbose_name_plural = "Students"
def __str__(self):
return '%s %s' % (self.first_name, self.last_name)
class SurgeryType(models.Model):
surgery_type = models.CharField("surgery_type", max_length=200)
sub_type = models.IntegerField(default=1)
available = models.BooleanField()
url = models.URLField(max_length=200, default='https://www.google.com')
def __str__(self):
return 'Type: ' + self.surgery_type + ' SubType : ' + str(self.sub_type)
Thank you
project/conf/base.py
ALLOWED_HOSTS = ['*']
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'core',
'rest_framework',
'rest_framework_swagger'
]
python django django-rest-framework django-views
python django django-rest-framework django-views
edited Nov 16 '18 at 12:39
Jade Dhangwattanotai
asked Nov 16 '18 at 10:49
Jade DhangwattanotaiJade Dhangwattanotai
54
54
2
Is your app is included in theINSTALLED_APPS?
– Abdul Niyas P M
Nov 16 '18 at 11:04
1
Please add yourINSTALLED_APPSfrom settings file in question
– Mohammad Umair
Nov 16 '18 at 12:08
Hi, I've added my INSTALLED_APPS
– Jade Dhangwattanotai
Nov 16 '18 at 12:39
add a comment |
2
Is your app is included in theINSTALLED_APPS?
– Abdul Niyas P M
Nov 16 '18 at 11:04
1
Please add yourINSTALLED_APPSfrom settings file in question
– Mohammad Umair
Nov 16 '18 at 12:08
Hi, I've added my INSTALLED_APPS
– Jade Dhangwattanotai
Nov 16 '18 at 12:39
2
2
Is your app is included in the
INSTALLED_APPS?– Abdul Niyas P M
Nov 16 '18 at 11:04
Is your app is included in the
INSTALLED_APPS?– Abdul Niyas P M
Nov 16 '18 at 11:04
1
1
Please add your
INSTALLED_APPS from settings file in question– Mohammad Umair
Nov 16 '18 at 12:08
Please add your
INSTALLED_APPS from settings file in question– Mohammad Umair
Nov 16 '18 at 12:08
Hi, I've added my INSTALLED_APPS
– Jade Dhangwattanotai
Nov 16 '18 at 12:39
Hi, I've added my INSTALLED_APPS
– Jade Dhangwattanotai
Nov 16 '18 at 12:39
add a comment |
1 Answer
1
active
oldest
votes
Fix the import in your urls.py.
It should be from core.views import SurgeryView instead of from apps.core.views import SurgeryView
1
Thanks! I got it to work now
– Jade Dhangwattanotai
Nov 17 '18 at 18:02
add a comment |
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%2f53336340%2fdjango-rest-framework-url-filter-import-views-error%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
Fix the import in your urls.py.
It should be from core.views import SurgeryView instead of from apps.core.views import SurgeryView
1
Thanks! I got it to work now
– Jade Dhangwattanotai
Nov 17 '18 at 18:02
add a comment |
Fix the import in your urls.py.
It should be from core.views import SurgeryView instead of from apps.core.views import SurgeryView
1
Thanks! I got it to work now
– Jade Dhangwattanotai
Nov 17 '18 at 18:02
add a comment |
Fix the import in your urls.py.
It should be from core.views import SurgeryView instead of from apps.core.views import SurgeryView
Fix the import in your urls.py.
It should be from core.views import SurgeryView instead of from apps.core.views import SurgeryView
answered Nov 16 '18 at 13:18
mostafazhmostafazh
1,990921
1,990921
1
Thanks! I got it to work now
– Jade Dhangwattanotai
Nov 17 '18 at 18:02
add a comment |
1
Thanks! I got it to work now
– Jade Dhangwattanotai
Nov 17 '18 at 18:02
1
1
Thanks! I got it to work now
– Jade Dhangwattanotai
Nov 17 '18 at 18:02
Thanks! I got it to work now
– Jade Dhangwattanotai
Nov 17 '18 at 18:02
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.
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%2f53336340%2fdjango-rest-framework-url-filter-import-views-error%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

2
Is your app is included in the
INSTALLED_APPS?– Abdul Niyas P M
Nov 16 '18 at 11:04
1
Please add your
INSTALLED_APPSfrom settings file in question– Mohammad Umair
Nov 16 '18 at 12:08
Hi, I've added my INSTALLED_APPS
– Jade Dhangwattanotai
Nov 16 '18 at 12:39