Reputation: 2377
I have the following code and an error that says 'inconsistent use of spaces and indentation' but I cannot see what has been done wrong?
class Song(models.Model):
album=models.ForeignKey(Album, on_delete=models.CASCADE)
file_type=models.CharField(max_length=10)
song_title=models.CharField(max_length=250)
def __str__(self):
return self.song_title
The code above it for another class is exactly the same, but it works
class Album(models.Model):
artist=models.CharField(max_length=250)
album_title=models.CharField(max_length=500)
genre=models.CharField(max_length=100)
album_logo=models.CharField(max_length=1000)
def __str__(self): #this is a string representation of this object - useful for testing/viewing purposes
return self.album_title+""+self.artist
The error appears to be in the line that returns the string representation of the Song object
def __str__(self):
return self.song_title
More specifically the error seems to point to this line:
def __str__(self): (if you note its position above int he Song class, the indentation looks fine...)
Can anyone spot the error or suggest a fix?
Upvotes: 0
Views: 891
Reputation: 653
This error occurs when you use the 'tab' button to indent your code in some places, but spacing in other. You just need to make sure you use either tabs or spaces throughout the whole file.
Find out which you use most often then adjust the outlier to the same method.
Upvotes: 2