Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: 'module' object has no attribute 'Datefield'

Tags:

python

django

In the file models.py

from django.db import models

# Create your models here.

class Publisher(models.Model):
    name = models.CharField(max_length=30)
    address = models.CharField(max_length=50)
    city = models.CharField(max_length=60)
    state_province = models.CharField(max_length=30)
    country = models.CharField(max_length=50)
    website = models.URLField()

class Author(models.Model):
    first_name = models.CharField(max_length=30)
    last_name = models.CharField(max_length=40)
    email = models.EmailField()

class Books(models.Model):
    title = models.CharField(max_length=100)
    authors = models.ManyToManyField(Author)
    publishers = models.ForeignKey(Publisher)
    publication_date = models.Datefield()

When I run the command

$ python manage.py validate

I get the error message

AttributeError: 'module' object has no attribute 'Datefield'

Please help.

like image 879
John Tan Avatar asked Feb 21 '26 10:02

John Tan


1 Answers

It should be models.DateField with a capital F.

So your Books model should look like this:

class Books(models.Model):
    title = models.CharField(max_length=100)
    authors = models.ManyToManyField(Author)
    publishers = models.ForeignKey(Publisher)
    publication_date = models.DateField()  # <--- Typo was here
like image 176
Shawn Chin Avatar answered Feb 24 '26 01:02

Shawn Chin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!