Tuesday, January 29, 2013

Re: Bulk db insert with a file through admin form

What I ended up doing is customizing the ModelAdmin for the Product class.  I went this route instead of adding a new form because I wanted to be able to use the admin form to search for a particular product or products, and once located, upload the serialized product file.

The admin effectively adds a file upload form to each product in the change list.  I also customized the change_list.html admin template to add a submit button to the form when a file was selected for uploading.  When that button is pressed, a view is called which parses the uploaded files and creates the ProductItem rows in db.

While researching, I found a useful tool for easily adding pages to the django admin: https://github.com/jsocol/django-adminplus


On Tuesday, December 4, 2012 6:24:34 AM UTC-7, אברהם סרור wrote:
I also have a case where I would need to bulk add items from a file, the client receives an excel file with products (up to a couple of hundreds).
I still haven't implemented nothing yet as the feature doesn't have priority, in any case I thought adding a file upload option on the admin, or maybe a bulk add option in manage would make more sense.

in any case I don't think it would be the case of changing your model as you don't need to store this info (the file name).

in any case I believe you would need to add something custom, maybe someone has some kind of template code for bulk adding from file, I believe this could be fairly common.

any thoughts? please update on the path you took.

best luck
avraham


On Tue, Dec 4, 2012 at 5:32 AM, MNG1138 <ma...@adperk.com> wrote:
Say I've got a model like this:

class Product(models.Model):
name = models.CharField(max_length=200)

class ProductItem(models.Model):
     product = models.ForeignKey(Product)
     serialnumber = models.charField()
     sold = models.BooleanField(default=False)

ProductItem represents physical products in the store.  I have a file with thousands of serial #'s for the product.  In the product form in the admin, I'd like to upload this file, parse the serial #'s and create rows in ProductItem.  I could add a FileField to Product and create a custom storage that parses the file and creates ProductITems.  Or I could override save for the Product model.  Both of these solutions are non-optimal, as I will have a FileField in Product and db that I don't need.

Is there any way to add a 'dummy' FileField just for the form that doesn't result in a DB row?  Or is the answer to create a custom admin form?  Any good tutorials or examples for doing creating a custom admin form?

Thanks,
Mark



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/efDj8ZO4QXIJ.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

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

No comments:

Post a Comment