首页 \ 问答 \ 为SAP中的MM模块生成ERD等数据库架构图(Generate a database schema diagram like ERD for MM module in SAP)

为SAP中的MM模块生成ERD等数据库架构图(Generate a database schema diagram like ERD for MM module in SAP)

如何生成数据库模式级ERD图。

此图将显示MM模式等架构中所有表之间的关系。


How can i generate a database schema level ERD diagram.

This diagram will show relationships between all tables in a schema like MM schema.


原文:https://stackoverflow.com/questions/31229638
更新时间:2023-05-23 09:05

最满意答案

有很多解决方案。 您可以使用多种类型的字段,例如StringRelatedField或SerializerMethodField。

以下是自定义相关字段的示例:

from rest_framework import serializers


class TrackField(serializers.RelatedField):

    def to_representation(self, value):
        return value.album_name


class TrackSerializer(serializers.ModelSerializer):

    album = TrackField(queryset=Album.objects.all())

    class Meta:
        model = Track
        fields = ('album', 'order', 'title', 'duration')

这会产生:

track = Track.objects.get(...)

TrackSerializer(track).data  # Returns {'album': <name of the album>, ...}

class BaseSerializer(serializers.ModelSerializer):
    """
    A Base Serializer that takes an additional `fields` argument that
    controls which fields should be displayed.
    """

    def __init__(self, *args, **kwargs):
        # Don't pass the 'fields' arg up to the superclass
        fields = kwargs.pop('fields', None)
        exclude = kwargs.pop('exclude', None)
        # Instantiate the superclass normally
        super(BaseSerializer, self).__init__(*args, **kwargs)

        if fields:
            # Drop any fields that are not specified in the `fields` argument.
            allowed = set(fields)
            existing = set(self.fields.keys())
            for field_name in existing - allowed:
                self.fields.pop(field_name)
        if exclude:
            # Drop fields that are specified in the `exclude` argument.
            excluded = set(exclude)
            for field_name in excluded:
                try:
                    self.fields.pop(field_name)
                except KeyError:
                    pass

I used the above class to explicitly exclude the arguments I did not want,

Credit : How to exclude parent when serializer is nested when using Django REST Framework?

相关问答

更多
  • 1.为什么要使用序列化器? 他们的目的是什么? 以一般的方式: 想象一下,你想邀请你的朋友喝杯咖啡。 为了通知你的朋友,你发短信“什么:咖啡,时间:12小时,在哪里:角落里的花式咖啡吧”。 本文是您的想法的序列化。 DRF为您的Django模型执行此操作。 想象一下,你有一个不想(想)了解你的DB或Django模型的JS客户端。 您将Django对象序列化为JSON,以便以JS兼容的方式提供该数据: data = { "address": { "street": "Fancy Str ...
  • 首先我要说的是,我非常确定你得到的错误是在Image_ComponentSerializer上添加.create方法之前。 由于Image_Component基于2个外键,如果你想在API中选择包含两个外键的字段,只需将序列化器更改为此(删除.create方法,因为不需要): class Image_ComponentSerializer(serializers.ModelSerializer): class Meta: model = Image_Component 因此,没有自 ...
  • 根据验证错误消息处理异常可能有点反模式,您可能会后悔走这条路。 解决此问题的一种方法是检查引发异常的条件 - 在它变为异常之前。 我没有您的应用程序的任何详细信息,但另一种选择是覆盖rest_auth序列化程序中的“验证”方法。 这将允许您首先检查条件(在rest_auth之前)并根据需要处理它。 这个项目的好处是它们是开源的,你可以查看源代码来看看它是如何引发这个错误的。 class SpecialValidator(LoginSerializer): def validate(self, attr ...
  • 在我的get函数中,我只是通过返回None来处理它。 In my get function, I just handled it by returning None.
  • 您正在以错误的方式访问数据。 您应该访问序列化程序中的.data而不是.data 。 m = CartSerializer(data=inputdata) if m.is_valid(): items = m.validated_data # access validated data here 为什么serializer.data方法不适合你的情况? 当你在做.data ,序列化器会尝试序列化initial_data因为你没有传递instance参数。 它会期望所有的字段都存在,但由于cart_ ...
  • 确保您的请求以json内容类型执行。 HTML表单不支持嵌套序列化器。 My serializers.py was messed up a little. I needed to remove the for loop for past_data since it was a one-to-one and just map that directly. Corrected file below: from rest_framework import serializers from conjugations ...
  • 我可能完全错误地回答了这个问题,因为我现在没有设置测试环境,但我会尽我所能。 好的,在测试环境中尝试过,下面的解决方案对我有用。 我不相信在这种情况下需要RelatedField,因为您为两个任意字段指定了related_name,您只需要在字段元组中引用相关名称,而不是在序列化程序中使用RelateField指定它们。 所以你可能会对此很好: class FooSerializer(serializers.ModelSerializer): class Meta: model = ...
  • 有很多解决方案。 您可以使用多种类型的字段,例如StringRelatedField或SerializerMethodField。 以下是自定义相关字段的示例: from rest_framework import serializers class TrackField(serializers.RelatedField): def to_representation(self, value): return value.album_name class TrackSeri ...
  • 由于akaphenom说您必须在序列化程序中使用related_name,但由于您未在模型中指定任何名称,因此必须使用默认值,在本例中为teaser_set ,您的IdeaSerializer必须为: class IdeaSerializer(serializers.HyperlinkedModelSerializer): user = UserSerializer(many=False, read_only=True) tickers = ReverseTickerSerializer(m ...
  • 要创建处理不同类型请求的单个API端点,应该重写实现定制逻辑的方法。 默认情况下predefined functions for each http methods GET,PUT,POST,PATCH and DELETE都有predefined functions for each http methods GET,PUT,POST,PATCH and DELETE 。 举例来说,请参阅下面的代码块。 网址 url(r'^api-endpoint/', apiView.as_view(), namesp ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。