Python 表格内联管理,其中表格在多个表格中引用

Python 表格内联管理,其中表格在多个表格中引用,python,django,django-models,django-admin,Python,Django,Django Models,Django Admin,我正在寻找定制管理员,在那里我发现了tablarinline模型,它允许我们在同一页面上进行编辑。但我感到困惑,因为我的表格在多个地方都有参考。我不明白我应该把哪个模型做成表格内联的 例如,这是我的模型 class ProductType(ModelWithMetadata): name = models.CharField(max_length=150, help_text="type of product. ex - accessories, apparel")

我正在寻找定制管理员,在那里我发现了
tablarinline
模型,它允许我们在同一页面上进行编辑。但我感到困惑,因为我的表格在多个地方都有参考。我不明白我应该把哪个模型做成表格内联的

例如,这是我的模型

class ProductType(ModelWithMetadata):
    name = models.CharField(max_length=150, help_text="type of product. ex - accessories, apparel")
    slug = models.SlugField(max_length=150, unique=True)
    is_shipping_required = models.BooleanField(default=True)

    class Meta:
        ordering = ("slug",)
        app_label="products"

class Category(MPTTModel, ModelWithMetadata):
    name = models.CharField(max_length=128)
    slug = models.SlugField(max_length=128)
    description = models.TextField(blank=True)
    parent = models.ForeignKey(
        "self", null=True, blank=True, related_name="children", on_delete=models.CASCADE
    )
    
    objects = models.Manager()
    tree = TreeManager()

    class Meta:
        verbose_name = "Category"
        verbose_name_plural = "Categories"

    def __str__(self):
        return self.name


class Product(ModelWithMetadata, PublishableModel):
    product_type = models.ForeignKey(
        ProductType, related_name="products", on_delete=models.CASCADE
    )
    name = models.CharField(max_length=128)
    slug = models.SlugField()
    category = models.ForeignKey(
        Category,
        related_name="products",
        on_delete=models.SET_NULL,
        null=True,
        blank=True,
    )
    isAvailable = models.BooleanField(default=True)
    isDiscount = models.BooleanField(default=False)
    charge_taxes = models.BooleanField(default=False)
    updated_at = models.DateTimeField(auto_now=True, null=True)

    class Meta:
        verbose_name = "product"
        verbose_name_plural = "products"
        ordering = ("name",)
        constraints = [
            models.UniqueConstraint(
                fields=["article_number", "slug"], name="unique article number and slug")
        ]

class ProductVariant(ModelWithMetadata):
    sku = models.CharField(max_length=255, unique=True)
    name = models.CharField(max_length=255, blank=True)
    currency = models.CharField(
        max_length=settings.DEFAULT_CURRENCY_CODE_LENGTH,
        default=settings.DEFAULT_CURRENCY,
        blank=True,
        null=True,
    )
    price_override_amount = models.DecimalField(
        max_digits=settings.DEFAULT_MAX_DIGITS,
        decimal_places=settings.DEFAULT_DECIMAL_PLACES,
        blank=True,
        null=True,
    )
    product = models.ForeignKey(
        Product, related_name="variants", on_delete=models.CASCADE
    )
    images = models.ManyToManyField("ProductImage", through="VariantImage")
    track_inventory = models.BooleanField(default=True)


class BaseAssignedAttribute(models.Model):

    assignment = None
    values = models.ManyToManyField("AttributeValue")


class AttributeValue(models.Model):

    name = models.CharField(max_length=250)
    value = models.CharField(max_length=100, blank=True, default="")
    slug = models.SlugField(max_length=255)
    attribute = models.ForeignKey(
        "Attribute", related_name="values", on_delete=models.CASCADE
    )


class AssignedProductAttribute(BaseAssignedAttribute):
    """Associate a product type attribute and selected values to a given product."""

    product = models.ForeignKey(
        Product, related_name="attributes", on_delete=models.CASCADE
    )
    assignment = models.ForeignKey(
        "ProductAttribute", on_delete=models.CASCADE, related_name="productassignments"
    )

    class Meta:
        unique_together = (("product", "assignment"),)


class AssignedVariantAttribute(BaseAssignedAttribute):
    """Associate a product type attribute and selected values to a given variant."""

    variant = models.ForeignKey(
        ProductVariant, related_name="attributes", on_delete=models.CASCADE
    )
    assignment = models.ForeignKey(
        "AttributeVariant", on_delete=models.CASCADE, related_name="variantassignments"
    )

    class Meta:
        unique_together = (("variant", "assignment"),)


class AttributeVariant(models.Model):
    attribute = models.ForeignKey(
        "Attribute", related_name="attributevariant", on_delete=models.CASCADE
    )
    product_type = models.ForeignKey(
        ProductType, related_name="attributevariant", on_delete=models.CASCADE
    )
    assigned_variants = models.ManyToManyField(
        ProductVariant,
        blank=True,
        through=AssignedVariantAttribute,
        through_fields=("assignment", "variant"),
        related_name="attributesrelated",
    )


class Attribute(models.Model):
    name = models.CharField(max_length=30, unique=True)
    slug = models.SlugField(max_length=250, unique=True)
    product_types = models.ManyToManyField(
        ProductType,
        blank=True,
        related_name="product_attributes",
        through="ProductAttribute",
        through_fields=("attribute", "product_type"),
    )
    product_variant_types = models.ManyToManyField(
        ProductType,
        blank=True,
        related_name="variant_attributes",
        through=AttributeVariant,
        through_fields=("attribute", "product_type"),
    )


class ProductAttribute(models.Model):
    attribute = models.ForeignKey(
        "Attribute", related_name="attributeproduct", on_delete=models.CASCADE
    )
    product_type = models.ForeignKey(
        ProductType, related_name="attributeproduct", on_delete=models.CASCADE
    )
    assigned_products = models.ManyToManyField(
        Product,
        blank=True,
        through=AssignedProductAttribute,
        through_fields=("assignment", "product"),
        related_name="attributesrelated",
    )
我对以下表格感到困惑:
AttributeValue
AssignedProductAttribute
AssignedVariantAttribute
AttributeVariant
Attribute
ProductAttribute
。属性与ProductAttribute相关,也与AttributeVariant和AttributeValue相关。同样,在变体的情况下

我无法确定哪个表应该是内联的,我应该在哪里引用该内联表。因为各种各样的关系,我不确定这些事情