views:

29

answers:

1

I get the following error:

sqlite3.OperationalError: table gallery_image has no column named filename

Here is my Model:

from django.db import models

class Image(models.Model):
    filename= models.Field(max_length=40);
    gallery = models.ForeignKey('Gallery')
    def __unicode__(self):
        return u'%s(%s)' % (self.filename,self.gallery)

class Gallery(models.Model):
    title   = models.CharField(max_length=100)
    url     = models.CharField(max_length=50, unique=True)
    def __unicode__(self):
        return u'title: %s, url: %s' % (self.title, self.url)

and this script apparently has an error in the very last line

from django.core.management.base import BaseCommand
from dev.gallery.models import Gallery, Image
import os

class Command(BaseCommand):
    def handle(self, *args, **options):
        importfrom='/srv/django/dev/gallery/import'
        exportto='/var/www/dev-media/'

        title=args[0]
        url=args[1]

        print(os.listdir(importfrom))

        if not len(args)==2:
            print 'wrong number of arguments'
            return ;

        #Create the gallery in the database
        g=Gallery(title=title,url=title)
        g.save();

        files=os.listdir('/srv/django/dev/gallery/import');

        for f in files:
            Image(filename=f,gallery=g).save();

if this makes sense to you, please explain to me why :)

+1  A: 

Should filename be an instance of FileField instead of just Field?

Lexo
thanks... should have been CharField since all i want to store is the actual name of the file not the location :)
niklasfi
Glad I could help :-)
Lexo