Hi All,

I need to export .CSV(example.csv) file data into my data base table . How
can I do this through command line.

My application


 blog/
    __init__.py
    models.py
    management/
        __init__.py
        commands/
            __init__.py
            csvexport.py
    views.py

How can I pass file name as argument...

csvexport.py

--------------

from django.core.management.base import BaseCommand

 class Command(BaseCommand):

  def handle(self, *app_labels, **options):

reader = csv.reader(csvfile, dialect='excel')

try:

for row in reader:

     column_first_name = row[4]

     column_last_name = row[5]

     column_middle_name = row[6]

    column_phone = row[8]

    column_email = row[9]

    column_age = row[0]

   column_address = row[12]

    column_city = row[13]

   column_state = row[14]

   column_zipcode = row[15]

     full_slug = column_first_name + ' ' + column_last_name

try:

   Person.objects.get_or_create(first_name=column_first_name,
last_name=column_last_name, middle_name=column_middle_name,
slug=slugify(full_slug), phone=column_phone, email=column_email,
age=column_age, address=column_address, city=column_city,
state=column_state, zipcode=column_zipcode)

  success = True

except Person.MultipleObjectsReturned:

      pass

 except IndexError:

         index_out_range = True





 Please advise.

Thanks

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to