我将仅过滤特定公司的数据。表之间的关系是ManyToMany,我使用的是django内联方法。公司被置于边缘和元数据模型中。
class Metadata(models.Model):
...
edges = models.ManyToManyField(Edge, verbose_name=_("edges"), related_name="metadata_edge", blank=True)
company = models.ForeignKey(Company, verbose_name=_("Company"), related_name="metadata", default=0, on_delete=0)
class Meta:
verbose_name = _("Metadata")
verbose_name_plural = _("Metadata")
class Edge(models.Model):
...
company = models.ForeignKey(Company, verbose_name=_("Company"), related_name="edges", default=0, on_delete=0)
class Meta:
verbose_name = _("edge")
verbose_name_plural = _("edges")
class Company(models.Model):
name = models.CharField(_("Name"), max_length=50)
class Meta:
verbose_name = _("company")
verbose_name_plural = _("companies")
admin.py
class MetadataEdgeInline(admin.TabularInline):
model = Metadata.edges.through
save_as = True
class MetadataAdmin(admin.ModelAdmin):
save_as = True
inlines = [MetadataEdgeInline,MetadataNodeInline, MetadataTemporaryInline]
exclude = ("edges", "nodes", "temporary_periods")
class EdgeAdmin(admin.ModelAdmin):
save_as = True
class CompanyAdmin(admin.ModelAdmin):
save_as = True
def get_queryset(self, request):
qs = super(CompanyAdmin, self).get_queryset(request)
return qs.filter(id=2)
如何在元数据网络表单中检索公司的边缘数据?现在,我在元数据Web表单中拥有所有优势。