定义许多应用程序共享的Django模型

时间:2016-09-23 19:15:51

标签: python django model-view-controller model

如何定义一个通用的Django模型(完全适合实用程序/通用模块),这将被许多应用程序使用?我更喜欢在应用程序之外定义它,因为在语义上它不属于任何一个。 可能吗?如何在应用程序之外处理它的迁移?

更具体地说,是用于分配用户或组织的国家/地区的模型:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:layout_centerHorizontal="true"
              android:orientation="vertical">

    <ListView
            android:id="@+id/files_list"
            android:background="@drawable/text_view_border"
            android:layout_height="0dp"
            android:layout_weight="1"
            ...
            android:soundEffectsEnabled="true" />

    <TextView
            android:id="@+id/result_text"
            ...
            android:layout_width="fill_parent"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:layout_height="wrap_content"
            android:gravity="center" />
</LinearLayout>

2 个答案:

答案 0 :(得分:1)

如果这些模型不属于任何应用,那么它们肯定可以在单独的应用中声明。我会创建一个全球性的&#39;具有您可能在其他应用中使用的模型和视图的应用。只要您使用&quot; startapp newapp&#39;来声明新应用,迁移就会照常运行。等

答案 1 :(得分:0)

如果它是基于您的示例中的用户的内容,请考虑extending the user model