views:

216

answers:

1

I'm using the admin interface to view invoices and products. To make things easy, I've set the products as inline to invoices, so I will see the related products in the invoice's form. As you can see I'm using a many-to-many relationship.

In models.py:

class Product(models.Model):
    name  = models.TextField()
    price = models.DecimalField(max_digits=10,decimal_places=2)

class Invoice(models.Model):
    company  = models.ForeignKey(Company)
    customer = models.ForeignKey(Customer)
    products = models.ManyToManyField(Product)

In admin.py:

class ProductInline(admin.StackedInline):
    model = Invoice.products.through

class InvoiceAdmin(admin.ModelAdmin):
    inlines = [FilteredApartmentInline,]
admin.site.register(Product, ProductAdmin)

The problem is that django presents the products as a table of drop down menus (one per associated product). Each drop down contains all the products listed. So if I have 5000 products and 300 are associated with a certain invoice, django actually loads 300x5000 product names. Also the table is not aesthetic.

I don't need the products to be updatable via the invoice form. How can I change it so that it'll just display the product's name in the inline table? Which form should I override, and how?

A: 

I think is simple, dont use the inline, just http://docs.djangoproject.com/en/1.2/ref/contrib/admin/#django.contrib.admin.ModelAdmin.filter_horizontal

diegueus9
That answers my question completely. But now I have a follow up - this shows the list of product names - what if I need it to be links to the products so I can link from the invoice to the products?
Jonathan
when you select the products in Invoice and save the object you links both objects
diegueus9