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

  • Home
  • SEARCH
  • 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 8430167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:32:06+00:00 2026-06-10T05:32:06+00:00

I am facing some problems with model.py file the code of model.py is: from

  • 0

I am facing some problems with model.py file

the code of model.py is:

from django.db import models

import datetime
from django.utils import timezone

class Poll(models.Model):
    question = models.CharField(max_length=200)
    pub_date = models.DateTimeField('date published')
 def __unicode__(self):
        return self.question
 def was_published_recently(self):
        return self.pub_date >= timezone.now() - datetime.timedelta(days=1)


class Choice(models.Model):
    poll = models.ForeignKey(Poll)
    choice = models.CharField(max_length=200)
    votes = models.IntegerField()
 def __unicode__(self):
        return self.choice

when i am run this command python manage.py shell the following error occurs

File "/home/ghrix/testing/demo/polls/models.py", line 9
    def __unicode__(self):
                         ^
IndentationError: unindent does not match any outer indentation level

this error occur after i add some lines of code in my model.py file

import datetime from django.utils import timezone

In Poll class

def __unicode__(self):
        return self.question
 def was_published_recently(self):
        return self.pub_date >= timezone.now() - datetime.timedelta(days=1)

In Choice class

def __unicode__(self):
        return self.choice
  • 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-10T05:32:07+00:00Added an answer on June 10, 2026 at 5:32 am

    Python is very sensitive to indentation. Your particular code should look like this:

    from django.db import models
    
    import datetime
    from django.utils import timezone
    
    class Poll(models.Model):
        question = models.CharField(max_length=200)
        pub_date = models.DateTimeField('date published')
    
        def __unicode__(self):
            return self.question
    
        def was_published_recently(self):
            return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
    
    
    class Choice(models.Model):
        poll = models.ForeignKey(Poll)
        choice = models.CharField(max_length=200)
        votes = models.IntegerField()
    
        def __unicode__(self):
            return self.choice
    

    Remember, the suggested indentation is 4 spaces for each level. The problem you’re having is that your attributes like say Poll.question should be defined at the same level as the method __unicode__.

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

Sidebar

Related Questions

I'm creating a application using entity framework code-first and i'm facing some problems with
I've moved from iOS applications development to android so I'm facing some problems finding
I'm facing some problems with my silverlight application. My application looks like an image
I am facing some problems for using placement new for contiguous memory.Please guide me,
I'm new to Android programming, so I'm facing some general problems about choosing the
I am facing a problem with urllib.url_encode in python. Bets explained with some code:
I am facing some strange behavior with file-name completion in emacs. C-x C-f to
I'm using graph api from youtube , and i am facing some trouble .
I am facing some problems, that is, In my application the gamecenter works fine
Im facing some problems, I looked around in the forum and didnt find any

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.