You need to move this line:
cardcost=Cardcost()
after this one:
for row in Mylist:
In your code you actually create ONE entity, and update it in the
loop. You need to create a new entity for each line in you csv file.
On Sep 5, 2:35 pm, VV <[EMAIL PROTECTED]> wrote:
> Hi guys,
> I'm trying to upload a .csv file and show the entities in a table.
> but the weird thing is it seems like the put() only stores the last
> record from the .csv file!
>
> here is the code to read the .csv file, store to big table and show
> the first 10 records:
>
> ===================
> class Processfile(webapp.RequestHandler):
> def post(self):
> cardcost=Cardcost()
> memfile=StringIO.StringIO(self.request.get('titles_file'))
> Mylist = csv.reader(memfile,dialect='excel')
>
> for row in Mylist:
> cardcost.Bom=row[0]
> cardcost.unitprice=row[1]
> print '%s %s ' % (cardcost.Bom, cardcost.unitprice)
> cardcost.put()
>
> print 'record fetched from datastore'
> cardcosts_query = Cardcost.all().order('-date')
> cardcosts = cardcosts_query.fetch(10)
> for cc in cardcosts:
> if cc.Bom:
> print '%s %s %s' % (cc.Bom,
> cc.unitprice,cc.date )
> else:
> print ' No value'
>
> class Cardcost(db.Model):
> Bom = db.StringProperty()
> unitprice=db.StringProperty()
> date = db.DateTimeProperty(auto_now_add=True)
>
> =======================
>
> here is the .csv file;
> =========
> BOM,Unit Price
> 13032341,1000
> 10421110,1200
> 23781234,780
> 34324321,3210
> 12346553,32
> 16781234,6789
> 112,5000
> ==========
>
> after clear up the datastore, here is the result after the first
> running:
> ========
> BOM Unit Price
> 13032341 1000
> 10421110 1200
> 23781234 780
> 34324321 3210
> 12346553 32
> 16781234 6789
> 112 5000
> record fetched from datastore
> 112 5000 2008-09-05 03:22:11.218000
> Status: 200 OK
> Content-Type: text/html; charset=utf-8
> Cache-Control: no-cache
> Content-Length: 0
> ========
>
> Is there anybody have similar problem or solution? Thanks.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---