Typically you would write a custom management command for this kind of thing:

https://docs.djangoproject.com/en/3.2/howto/custom-management-commands/

On April 29, 2021 11:05:29 AM CDT, 'Muhammad Asim Khaskheli' via Django users 
<[email protected]> wrote:
>
>Hi,
>
>I wanted to ask how to load CSV data into the model. What steps do we
>have 
>to follow?
>
>I have made this function but how exactly to run this code because,
>python 
>manage.py load data won't work. 
>
>def import_data():
>with open('sample-dataset.csv') as f:
>reader = csv.reader(f)
>for row in reader:
>if row[0] != 'user_id':
>_, created = Funnel.objects.get_or_create(
>user_id=row[0],
>event=row[1],
>timestamp=row[2],
>session_id=row[3]
>)
>
>Now, how to run this script?
>
>
>-- 
>You received this message because you are subscribed to the Google
>Groups "Django users" group.
>To unsubscribe from this group and stop receiving emails from it, send
>an email to [email protected].
>To view this discussion on the web visit
>https://groups.google.com/d/msgid/django-users/fefae867-8bc5-4d9a-a9e6-e0268d20632cn%40googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/65F082D0-CCBB-4FE5-9788-68716442A1D4%40fattuba.com.

Reply via email to