Last active
July 19, 2024 13:51
-
-
Save tobyl/deef5780a69a38f14884aaec86cbfab3 to your computer and use it in GitHub Desktop.
Nested inlines example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# models | |
class Part(models.Model): | |
title = models.CharField(max_length=255) | |
class PartAttribute(models.Model): | |
part = models.ForeignKey(Part, on_delete=models.CASCADE, null=True, related_name='attributes') | |
name = models.CharField(max_length=128) | |
class PartAttributeChoice(models.Model): | |
part = models.ForeignKey(Part, on_delete=models.CASCADE, null=True, related_name='choices') | |
part_attribute = models.ForeignKey(PartAttribute, on_delete=models.CASCADE, null=True, related_name='attributes') | |
name = models.CharField(max_length=128) | |
# admin | |
class PartAttributeChoiceInline(StackedInline): | |
model = PartAttributeChoice | |
fields = ('name',) | |
class PartAttributeInline(StackedInline): | |
model = PartAttribute | |
fields = ('name',) | |
inlines = (PartAttributeChoiceInline,) | |
@admin.register(Part, site=formula_admin_site) | |
class PartModelAdmin(ModelAdmin): | |
model = Part | |
fields = ('title',) | |
inlines = (PartAttributeInline, PartAttributeChoiceInline,) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment