小编Osw*_*ira的帖子

Tastypie REST上的ForeignKey - 模型''具有空属性

我需要列出每个员工的工作时间,但我得到:

模型''具有空属性'work_journey',并且不允许空值.

上:

/休息/ tastypie /雇员/?格式= JSON

models.py

class Employee():
    registration = models.CharField(u'Registration', max_length=20, unique=True)
    work_journey = models.ForeignKey(WorkJourney, null=True, blank=True)
Run Code Online (Sandbox Code Playgroud)

hr.models.py

class WorkJourney(ModelPlus):
    code = models.CharField(max_length=10, null=True, unique=True)
    workinghours = models.CharField(max_length=40)
    excluded = models.BooleanField()

    class Meta:
        db_table='work_journey'
        verbose_name = u'Work Journey'

    def __unicode__(self):
        return self.workinghours
Run Code Online (Sandbox Code Playgroud)

resources.py

from suap.models import Employee
from hr.models import WorkJourney


class WorkJourneyResource(ModelResource):
    class Meta:
        queryset = WorkJourney.objects.all()
        resource_name = 'work_journey'
        authentication = BasicAuthentication()

class EmployeeResource(ModelResource):
    journey = fields.ForeignKey(WorkJourney, 'work_journey')
    class Meta:
        queryset = Employee.objects.all()
        resource_name = …
Run Code Online (Sandbox Code Playgroud)

django rest tastypie

5
推荐指数
1
解决办法
4560
查看次数

标签 统计

django ×1

rest ×1

tastypie ×1