mysql - django 1.5 multiple joins -
i have 3 tables wish show relate each other 4th table name pivot
# manufacturer id | name # product id |name # part id| name # pivot id | part_name_fk | product_name_fk | manufacturer_name_fk ... , 5th table reference "pivot"
# report id |pivot_record_fk|this_week_use is correct way "relate" 3 entities, if how display in admin showing related entries ?
thanks.
you should have structured 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 can filter out based on part's name (if needed to) using:
report.objects.filter(manufacturer__product__part__name="nail") as admin, can add have display different properties of adding methods reportadmin class , referencing them in list_display property. can add them list_filter can filter out values.
Comments
Post a Comment