django Models cross file ---- 跨app引用文件

一、django 的跨app引用文件是通过import 来实现的,但是import 的路径查找和标准的import 不太一样,django里面更加方便了

 

二、例子

  1、project 结构说明

[jianglexing@workstudio fd]$ ll
total 4
drwxrwxr-x 3 jianglexing jianglexing  93 May 27 09:55 fd
drwxrwxr-x 4 jianglexing jianglexing 142 May 27 09:42 jiang
drwxrwxr-x 4 jianglexing jianglexing 157 May 27 09:59 le
-rwxr-xr-x 1 jianglexing jianglexing 800 May 27 09:35 manage.py

# fd      ---- project name
# jiang  ---- app name
# le      ---- app name

  2、jiang/models.py

# jiang/models.py

from django.db import models

# Create your models here.
class classJiang(models.Model):
    name=models.CharField(max_length=8)

  3、le/models.py 它会去引用jiang/models.py 文件中定义的classJiang

# le/models.py
from django.db import models
from jiang.models import classJiang #看到了吧、跨app引用、也好自然

# Create your models here.
class ClassLe(models.Model):
    name=models.CharField(max_length=8)

def testCrossFile():
    return str(classJiang)

  

 

----

posted on 2017-05-27 10:12  蒋乐兴的技术随笔  阅读(3632)  评论(0编辑  收藏  举报

导航