tags:

views:

56

answers:

2

IndexError: list index out of range

this is my django code :

import os
os.environ["DJANGO_SETTINGS_MODULE"] = "sphinx_test.settings"

#from django.core.management import setup_environ
#from sphinx_test import settings

#setup_environ(settings)


from django.db import models
from djangosphinx.models import SphinxSearch,SphinxQuerySet




class File(models.Model):
    name = models.CharField(max_length=200)
    tags = models.CharField(max_length=200) 

    objects = models.Manager()
    search  = SphinxQuerySet(index="test1")


import datetime



class Group(models.Model):
    name = models.CharField(max_length=32)

class Document(models.Model):
    group       = models.ForeignKey(Group)
    date_added  = models.DateTimeField(default=datetime.datetime.now)
    title       = models.CharField(max_length=32)
    content     = models.TextField()

    search      = SphinxQuerySet(File,index="test1")

    class Meta:
        db_table = 'documents'

and

Traceback (most recent call last):
  File "D:\zjm_code\sphinx_test\models.py", line 16, in <module>
    class File(models.Model):
  File "D:\Python25\Lib\site-packages\django\db\models\base.py", line 52, in __new__
    kwargs = {"app_label": model_module.__name__.split('.')[-2]}
IndexError: list index out of range
A: 

You need to set Meta.app_label to something usable.

Ignacio Vazquez-Abrams
how to set it ??like this :class Meta: app_label = sphinx_test
zjm1126
Inside the model class, yes.
Ignacio Vazquez-Abrams
hi ,it's ok ,and when i run my code ,it print nothing ,i want to know what happen on my databse (it's name is 'test')
zjm1126
coz,i found the 'test' databse don't create any table
zjm1126
... Your code doesn't contain any calls to create any tables, so I'm not really surprised that nothing is happening.
Ignacio Vazquez-Abrams
so how does change it ???
zjm1126
I thought that's what your other question was supposed to be asking...
Ignacio Vazquez-Abrams
A: 

That's odd, that part of the code is just supposed to determine your app name. See the section here starting line 45. What's your app name for this?

You may be able to avoid the error by setting app_label to the name of your app in the Meta section of your model.

Alex JL
There is no app; it's a standalone script.
Ignacio Vazquez-Abrams
Thanks... that explains why Django can't find the app name I guess!
Alex JL