Friday, October 25, 2013

Bulk add foreign keys in admin interface

I am using the following type of model setup:

class Product(models.Model):
    name = models.CharField(max_length=40)
    description = models.TextField(blank=True)
    active = models.BooleanField(default=True)
    priority = models.IntegerField(default=100)
    size_chart = models.ForeignKey(SizeChart)
    designer = models.ForeignKey(Designer)
    collections = models.ManyToManyField(Collection)
    categories = models.ManyToManyField(Category)
    price = models.DecimalField(max_digits=6, decimal_places=2)
    def __unicode__(self):
        return self.name

class Variation(models.Model):
    color = models.ForeignKey(Color)
    size = models.ForeignKey(Size)
    product = models.ForeignKey(Product)
    price_override = models.DecimalField(max_digits=6, decimal_places=2, blank=True)

I have Variations setup as TabularInline in Django admin.  However, there are > 200 different colors, and about 20 sizes.  Adding 10 different colors with 15 sizes is a lot of clicking for someone.  What I would like to do is add some type of dropdown where multiple colors, along with multiple Sizes, can be selected, and then all of the Variations will be created for the cross product of those two selections.

What I envision is having an area somewhere in the Django Admin for Product that is titled "Bulk Add" with drop down boxes for both Color and Size where multiple values for each can be selected.  When the user is happy with their selection, they will click a button and all of the Variations will be created and the user will be back to the product page with all of the options now visible in the TabularInline section.

Is this type of action possible?

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate