I am getting this error "type object 'Skills' has no attribute '_default_manager'"
I am getting the following error "type object 'Skills' has no attribute 'objects'" while trying to run my Django project
views.py
from django.shortcuts import render, get_object_or_404, redirect
from django.contrib.auth.decorators import login_required
from django.utils import timezone
from portfolio_app.models import GuestUser,InquiryForm,Skills,Facts,Education,Service,UserTestimonials
from .forms import GuestUser,InquiryForm,Skills,Facts,Education,Service,UserTestimonials
from django.views.generic import (TemplateView,ListView,
DetailView,CreateView,
UpdateView,DeleteView)
from django.views import generic
from django.urls import reverse_lazy
from django.contrib.auth.mixins import LoginRequiredMixin
class TestView(generic.ListView):
model = Skills
template_name = 'portfolio_app/test.html'
models.py
from django.db import models
from django.utils import timezone
from django.contrib.auth.models import User
from django.urls import reverse
class Skills(models.Model):
skill_name = models.CharField(max_length=100)
skill_value = models.CharField(max_length=50)
def __str__(self):
return self.skill_name
test.html
{% extends 'portfolio_app/base.html' %}
{% load static %}
{% block content %}
{% for skill in skills_list %}
{{skill.skill_name}}}
{% endfor %}
{% endblock %}
urls.py
from django.urls import path
from portfolio_app.models import *
from . import views
urlpatterns = [
path('',views.fact,name='index'),
#path('index/',views.SkillView.as_view,name='index'),
path('about/',views.about_me,name='about'),
path('service/',views.ServiceView.as_view(),name='service'),
path('resume/',views.ResumeView.as_view(),name='resume'),
path('contact/',views.ContactView.as_view(),name='contact'),
path('test/',views.TestView.as_view(),name='test'),
]
Please help I am getting the following error "type object 'Skills' has no attribute 'objects'" while trying to run my Django project
CodePudding user response:
You have ambiguous imports:
from portfolio_app.models Skills
from .forms Skills
You can change your model import like this:
from portfolio_app.models Skills as SkillsModel
and then use SkillsModel instead of Skills:
class TestView(generic.ListView):
model = SkillsModel
template_name = 'portfolio_app/test.html'
Or you can get rid of unnecessary .forms imports.
