Saturday, October 30, 2010

Re: Import csv file in admin

The ordinary user won't have to deal with the command line, you just
need to get the CSV file. A ModelForm to which an FileField is added
doesn't really have anything to do with that.

Instead, you should create a standard form with a single FileField to
upload the CSV file, save it temporarily or just keep it as a file
object and then process it as Jirka pointed out.

Regards,
Felix


On 29.10.2010 18:31, Jorge wrote:
> Jirka
>
> I need an easy method inside the admin to upload the csv file with an
> web interface. I guess with your method the admin will need access to
> the server and the command line, and something like this is not what i
> try to do, because the admin (not me) is not a django developer, not
> even a user get used to command lines. But if my guessing is wrong how
> can i do a web interface for your method?
>
> Regards!
>
> On Oct 29, 5:44 am, Jirka Vejrazka <jirka.vejra...@gmail.com> wrote:
>> I must still be missing something here. If all you want to do is to
>> read CSV file and save the data in the database, I still don't
>> understand why you use the forms machinery.
>>
>> You only *need* to use the data model, e.g.
>>
>> from myapp.models import Data
>>
>> csvfile = csv.reader('something.csv')
>>
>> for line in csvfile:
>> do_necessary_data_conversions_or_checks(line)
>> try:
>> Data.objects.create(field1=line[0], field2=line[1], ...)
>> except (IndexError, IntegrityError):
>> print 'Invalid line encountered:\n%s' % line
>>
>> What am I missing?
>>
>> Jirka
>

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment