我目前正在开发一个 django-tastypie 网络应用程序。我有两个 django 模型:
class Student(models.Model):
name = models.CharField()
class Course(models.Model):
name = models.CharField()
student = models.ForeignKey(Student)
由此,我在两个不同的文件中有两个 Tastypie 资源。但是我的问题来了。我希望能够从课程中过滤学生,并从学生中过滤课程:
from website.api.course import CourseResource
class StudentResource(ModelResource):
course = fields.ForeignKey(CourseResource, "course")
class Meta:
queryset = Student.objects.all()
resource_name = "student"
filtering = { "course" : ALL }
和
from website.api.student import StudentResource
class CourseResource(ModelResource):
student = fields.ForeignKey(StudentResource, "student")
class Meta:
queryset = Course.objects.all()
resource_name = "course"
filtering = { "student" : ALL }
但当然,我遇到了一个循环导入问题。我怎么能解决这个问题?
谢谢 !