i have a generate(variable) function in another file, i want to call it in my models.py file. here is my code.
class Season(models.Model):
Year = models.CharField(max_length=6, default=getyear())
start_date = models.DateField()
end_date = models.DateField()
league = models.ManyToManyField(League)
fixgen = models.BooleanField(default=False)
in_progress = models.BooleanField(default=True)
def __unicode__(self):
return self.Year
def createfixtures(self):
generate(self)
but when i run the file, it gives me the following error.
Validating models...
Unhandled exception in thread started by <function inner_run at 0xa05eae4>
Traceback (most recent call last):
File "/usr/lib/pymodules/python2.7/django/core/management/commands/runserver.py", line 48, in inner_run
self.validate(display_num_errors=True)
File "/usr/lib/pymodules/python2.7/django/core/management/base.py", line 249, in validate
num_errors = get_validation_errors(s, app)
File "/usr/lib/pymodules/python2.7/django/core/management/validation.py", line 35, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/usr/lib/pymodules/python2.7/django/db/models/loading.py", line 146, in get_app_errors
self._populate()
File "/usr/lib/pymodules/python2.7/django/db/models/loading.py", line 64, in _populate
self.load_app(app_name)
File "/usr/lib/pymodules/python2.7/django/db/models/loading.py", line 78, in load_app
models = import_module('.models', app_name)
File "/usr/lib/pymodules/python2.7/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/yousuf/PycharmProjects/CricketManager/../CricketManager/Cricket/models.py", line 4, in <module>
from Cricket.fixtures import generate
File "/home/yousuf/PycharmProjects/CricketManager/Cricket/fixtures.py", line 3, in <module>
from Cricket.models import League, Season, Team, Fixture
File "/home/yousuf/PycharmProjects/CricketManager/Cricket/models.py", line 4, in <module>
from Cricket.fixtures import generate
ImportError: cannot import name generate
can i import a function that works fine if i call it from django shell. now i want to have it as part of django admin menu.
if somebody can look at it, and see what the problem is, or what is the work around for it.
//yousuf