Note that there are some explanatory texts on larger screens.

plurals
  1. POimport csv file into mysql database using django web application
    primarykey
    data
    text
    <p>thanks guys.i managed to complete it.million thanks again specially for DAVID,WM-EDDIE and S.LOTT.also STACKOVERFLOW</p> <p>The solution:</p> <pre><code> **model = Contact() model.contact_owner = request.user model.contact_name = row[1] model.contact_mobile_no = row[2] model.select_group = row[3] model.save()** </code></pre> <p>my user.py</p> <pre><code>def import_contact(request): if request.method == 'POST': form = UploadContactForm(request.POST, request.FILES) if form.is_valid(): csvfile = request.FILES['file'] print csvfile csvfile.read() testReader = csv.reader(csvfile,delimiter=' ', quotechar='|') **#what code should i write here to store data in mysql** for row in testReader: print "|".join(row) return HttpResponseRedirect('/admin') else: form = UploadContactForm() vars = RequestContext(request, { 'form': form }) return render_to_response('admin/import_contact.html', vars) </code></pre> <p>the data in csv file:</p> <p>abubakar,rooney,0178222123,student</p> <p>abubakar,ronaldo,0183886789,student</p> <p>abubakar,kaka,0197887898,bola</p> <p><strong>appreciated any suggestion.and hopefully can show me some coding example coz i'm still beginner in this language</strong></p> <p>my models.py:</p> <pre><code>class Contact(models.Model): contact_owner = models.ForeignKey(User, related_name="contacts") contact_name = models.CharField(max_length=20) contact_mobile_no = models.CharField(max_length=20) select_group = models.CharField(max_length=20, null=True) def __unicode__(self): return "contact {contact_owner=%s, contact_name=%s, contact_mobile_no=%s, select_group=%s}" % (self.contact_owner, self.contact_name, self.contact_mobile_no, self.select_group) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload