1

Can someone please give me a quick explanation as to what I'm doing wrong when calling about.objects.all() and cv.objects.all(). I tested them in the shell and got the same error.

from django.shortcuts import render
from resume.models import websites, about, cv
from django.http import HttpResponse


def about_text(request):
    about_text = about.objects.all()
    context_dict = {'text': about_text}

    response = render(request, 'resume.html', context_dict)
    return response 



def cv(request):
    position = cv.objects.all()
    context = {'job': position}

    response = render(request, 'resume.html', context_dict)
    return response

models

from django.db import models
from django.utils import timezone

class cv(models.Model):
    title = models.CharField(max_length=128)
    company = models.CharField(max_length=128)
    started = models.DateField()
    ended = models.DateField()
    roles = models.TextField()

    def __unicode__(self):
        return self.position


class about(models.Model):
    text = models.TextField()

    def __unicode__(self):
        return self.text

traceback error

Request Method: GET
Request URL: http://127.0.0.1:8000/resume/test

Django Version: 1.7.3
Python Version: 2.7.6
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'resume',
 'blog')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware')


Traceback:
File "c:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response
  111.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\WriteCode\test_env\portfolio\resume\views.py" in cv
  16.   position = cv.objects.all()

Exception Type: AttributeError at /resume/test
Exception Value: 'function' object has no attribute 'objects'

2 Answers 2

3

Your view's name and model's name are both cv. You need to change your view's name to something else. (maybe get_all_resumes)

def get_all_resumes(request):
    position = cv.objects.all()
    context = {'job': position}

    response = render(request, 'resume.html', context)
    return response
Sign up to request clarification or add additional context in comments.

1 Comment

Of course, knew it was something simple. Thank you ozgurv.
2

In addition to ozgurv's answer, you could also import resume.models as resume_models and then refer to the cv class like this: resume_models.cv.objects.all(). I don't think it's a better solution but it's worth mentioning.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.