1

I'm building a personal photography site using Django. I'm working on the models.py. My app is called "photoViewer", the site is called "photoSite". However, when I run makemigrations, I'm getting:

NameError: name 'ImageField' is not defined

I have 3 images stored in "photoSite\photoViewer\static\photoViewer\images" locally, that I'd like to display on my completed site.

Models.py:

from django.db import models

# Create your models here.
class Photo (models.Model):
    photo_title = models.CharField(max_length=200)
    photo_img = ImageField(upload_to = "images/") #Error here
    def __str__(self):              # __unicode__ on Python 2
        return self.photo_title
class Album (models.Model):
    photos= models.ManyToManyField(Photo)
    album_title = models.CharField(max_length=200)

    def __str__(self):              # __unicode__ on Python 2
        return self.album_title

settings.py:

...
MEDIA_ROOT = os.path.join(os.path.dirname(__file__), '..', 'static').replace('\\','/')
STATIC_URL = '/static/'
...
jerryh91
  • 1,777
  • 10
  • 46
  • 77

1 Answers1

7

Looks like you have a syntax issue...

photo_img = ImageField(upload_to = "images/")

Should be...

photo_img = models.ImageField(upload_to = "images/")
Billy
  • 138
  • 1
  • 6