Can I Use models class since other file create manually?

时间:2015-05-12 22:51:11

标签: python django django-models

the files are

$('#calendar').fullCalendar({

    header: {
        left: 'prev,next today',
        center: 'title',
        right: 'month,agendaWeek,agendaDay'
    },
    allDay: true,
    editable: true,
    eventLimit: false,

    selectable: true,
    selectHelper: true,

    dayClick: function(start, end, allDay) {
        var title = prompt('Create an event:');
        if (title) {
            calendar.fullCalendar('renderEvent', {
                    title: title,
                    start: start,
                    end: end,
                    allDay: allDay
                },
                true // make the event "stick"
            );
        }
        calendar.fullCalendar('unselect');
    },

    googleCalendarApiKey: 'AIzaSyA2obQBQF_npk4rq-nU-X5kYfIkuWsBJkY',
    events: {
        googleCalendarId: 'efxpromedia.com_jvm3li2c2jva0f9hd89lt5hikg@group.calendar.google.com',

    },
    eventClick: function(event) {
        // opens events in a popup window
        window.open(event.url, 'gcalevent', 'width=800,height=700');
        $(this).css('border-color', 'red');
        return false;
    },
}); //CALENDAR
}

I created manually a file call import.py that contains:

app
       __init__.py
       admin.py
       import.py
       models.py
       tests.py
       views.py

In models.py that contains

from models import Category

then I need to execute import.py file since shell, but I need Use models from Django. I execute

from django.db import models
class Category(models.Model):

    name = models.CharField(max_length = 25, unique = True)
    description = models.TextField(blank=True)

    def __unicode__(self):
        return "%s, %s" % (self.name, self.description)

    class Meta:
        verbose_name = "Category"
        verbose_name_plural = "Categories"

I have this error:

python manage.py shell < .\models\import.py

1 个答案:

答案 0 :(得分:0)

You should specify the full module name:

/User

Or use the relative import:

from app.models import Category