Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8501575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:15:00+00:00 2026-06-11T01:15:00+00:00

I have a django app and I need to import existing data from text

  • 0

I have a django app and I need to import existing data from text files into the new database.
Usually I would do something like this:

for i in lines():
    a = Mymodel()
    a.field1 = i[0]
    a.field2 = i[0]
    a.save()

this works fine, but no data validation takes place (except for the matching data type of the fields).

For inputting data via the webinterface, I wrote some ModelForm forms, which do all the data validation for me (in the clean() method). I do know how to populate and validate a form using request.POST as an input, but is it also possible to do the same on python shell? Can I somehow feed my original data into a dict and populate the form with these data?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T01:15:01+00:00Added an answer on June 11, 2026 at 1:15 am

    yes,

    in forms.py

    class FormA(forms.ModelForm):
       class Meta:
          model = Mymodel
       def clean_field1(self):
          #logic here
          #return cleaned field1
    

    in views.py

     def populate_dict(line):
         dict = {'field1': line[0], 'field2': line[2], ... }
         return dict
    
     def populate(request):
        for line in lines():
           initial = populate_dict(line)
           form = FormA(initial=initial)
           if form.is_valid():
             form.save()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Django app that gets it's data completely from an external source
I have a django app with some model for uploading files. I need to
I am using django-registration app. and have following code in forms.py from django.contrib.auth.forms import
I have a Django app that use a django-tagging. I need to port this
I have a place in my Django app where I need to construct a
I have a django app that I made and have implemented a plist into
I need to pass a dictionary from a python script to a Django app.
I have a django-app using sites framework and need to deploy in a single
I have the following situation. Project files was stored in ~/django-apps/app-old/app. For some reasons
I have this app https://github.com/staticdev/django-crud-utils that need to have django-sorting installed to work. But

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.