Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8371619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:12:25+00:00 2026-06-09T14:12:25+00:00

My website has a system of alerts. When a certain action occurs the system

  • 0

My website has a system of alerts. When a certain action occurs the system loggs an alert in the following model:

class Alert(models.Model):
    title = models.CharField(max_length=60)
    read = models.BooleanField #if this is a new alert of not
    for_user = models.ForeignKey(User) #which user will see it
    link = models.CharField(max_length=100)

Many functions need to check the number of alerts a user has (Mostly to display the number of new alerts next to the alerts tab of the site). Because of that, I created this function:

@login_required()
def get_alertnum(user):
    alert_objects = Alert.objects.filter(read = False, for_user=user)
    num = 0
    for n in alert_objects:
        num += 1
    return num

Which is accessed by this function:

@login_required()
def posting_draft(request):
    user = request.user
    user_drafts = Draft.objects.filter(user = user)
    drafts = dict()
    for d in user_drafts:
        drafts[d.title] = d.id
    alertnum = get_alertnum(user)
    return render_to_response('posting_draft.html', {'STATIC_URL':STATIC_URL, 'draft_l' : drafts, 'selected':"dr", alertnum: alertnum})

But I get the following error:

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/posting/drafts

Django Version: 1.4
Python Version: 2.7.3
Installed Applications:
('django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'Knights',
 'django.contrib.admin')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')


Traceback:
File "/Library/Python/2.7/site-packages/Django-1.4-py2.7.egg/django/core/handlers/base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "/Library/Python/2.7/site-packages/Django-1.4-py2.7.egg/django/contrib/auth/decorators.py" in _wrapped_view
  20.                 return view_func(request, *args, **kwargs)
File "/Users/Mike/Desktop/Main/Django-Development/BBN/Knights/views.py" in posting_draft
  245.     alertnum = get_alertnum(user)
File "/Library/Python/2.7/site-packages/Django-1.4-py2.7.egg/django/contrib/auth/decorators.py" in _wrapped_view
  19.             if test_func(request.user):
File "/Library/Python/2.7/site-packages/Django-1.4-py2.7.egg/django/utils/functional.py" in inner
  185.         return func(self._wrapped, *args)

Exception Type: AttributeError at /posting/drafts
Exception Value: 'User' object has no attribute 'user'
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T14:12:27+00:00Added an answer on June 9, 2026 at 2:12 pm

    You need to remove @login_required() decorator from the get_alertnum() function. The decorator assumes the first argument is a request object and is trying to access the user attribute.

    Also you could simplify and speed up the function by:

    def get_alertnum(user):
        return Alert.objects.filter(read=False, for_user=user).count()
    

    Below is an explanation of the count method.

    https://docs.djangoproject.com/en/dev/ref/models/querysets/#count

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My website has a sponsorship system that allows users to invite friends by email
Currently, I have a semi-dynamic system for my website's pages. head.php has all the
I am building a website that has a system where users can send messages
My development website has a traffic light graphic system to illustrate stock levels for
I need to scrape a website that has a basic folder system, with folders
My website has a very granular permissions system for every client, making it fairly
I am creating an Ad system for an ASP.NET website. The website has a
I have a PHP based website which has a post/comment system. Can I add
I'm building a website which has a feature which ressembles SE's voting system. I'm
I am managing a website which has about 140.000 documents. This system had been

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.