I am trying to learn, "How to run standalone scripts in django". I am using python2.7 and django==1.4.3. I have created a very basic script which i am trying to run but facing import errors . I don't want to create a management command as this is just temporary stuff and my focus is to learn also.
My Code
import os
import sys
from cartridge.shop.models import HomepageUpselling
class HomepageUpsellingToBestsellers():
"""This class copy the HomepageUpselling data to BestSellers"""
def homepageuselling_to_bestsellers(self):
""" Data Copy """
hu_obj = HomepageUpselling.objects.all()
for hu_iterable in hu_obj:
bs_obj, created = \
BestSeller.objects.get_or_create(product=hu_iterable.product,
variation=hu_iterable.variation)
print "BestSeller data copying %s" % bs_obj.id
return
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project_name.setttings")
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from django.core.management import execute_from_command_line
hu_to_bs_obj = HomepageUpsellingToBestsellers()
hu_to_bs_obj.homepageuselling_to_bestsellers()
print "Data Copied"
Error
ImportError: No module named cartridge.shop.models