[Answer]-Django 1.5 multiple joins

1👍

You should have it structured like so.

class Manufacturer(models.Model):
    name = models.CharField()

class Product(models.Model):
    name = models.CharField()
    manufacturer = models.ForeignKey(Manufacturer, related_name="products")

class Part(models.Model):
    name = models.CharField()
    manufacturer = models.ForeignKey(Product, related_name="parts")

class Report(models.Model):
    manufacturer = models.ForeignKey(Manufacturer, related_name="reports")
    this_week_use

Then in Report you can filter out based on the part’s name (if you needed to) by using:

Report.objects.filter(manufacturer__product__part__name="Nail")

As for the admin, you can add have it display the different properties of it by adding methods to the ReportAdmin class and then referencing them in the list_display property. You can also add them to the list_filter so that you can filter out by values.

Leave a comment