Writing my first Django app - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html) +--- Thread: Writing my first Django app (/thread-20593.html) |
Writing my first Django app - sunny_awesome - Aug-21-2019 Hey Guys, I am following along Django official documentation for learning Django. I am now in Part 2 (Writing your first Django app) I have made some changes to polls/models.py like this from django.db import models class Question(models.Model): # ... def __str__(self): return self.question_text def was_published_recently(self): return self.pub_date >= timezone.now() - datetime.timedelta(days=1) class Choice(models.Model): # ... def __str__(self): return self.choice_textBut when I run this command: [python] python manage.py makemigrations [\python] I am getting an error in command line like this: Can somebody help me figure this error out?
RE: Writing my first Django app - fishhook - Aug-21-2019 Make sure you didn't mix TABS and SPACES. Show your whole module. RE: Writing my first Django app - sunny_awesome - Aug-22-2019 Thanks for the reply, fishhook. Here's my models.py file: from django.db import models # Create your models here. class Question(models.Model): question_text = models.CharField(max_length=200) pub_date = models.DateTimeField('date published') def __str__(self): return self.question_text def was_published_recently(self): return self.pub_date >= timezone.now() - datetime.timedelta(days=1) class Choice (models.Model): question = models.ForeignKey(Question, on_delete=models.CASCADE) choice_text = models.CharField(max_length = 200) votes = models.IntegerField(default=0) class __str__(self): return self.choice_text RE: Writing my first Django app - fishhook - Aug-22-2019 class __str__(self): return self.choice_textClass definition is not suitable here, you probably wanted to write def instead. RE: Writing my first Django app - sunny_awesome - Aug-27-2019 Thank you so much fishhook. I got it. Sunil |