django - ForeignKey on Tastypie REST - The model '' has an empty attribute -
i need list working hours of each employee, i'm getting:
the model '' has empty attribute 'work_journey' , doesn't allow null value.
on:
/rest/tastypie/employee/?format=json
models.py
class employee(): registration = models.charfield(u'registration', max_length=20, unique=true) work_journey = models.foreignkey(workjourney, null=true, blank=true)
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): homecoming self.workinghours
resources.py
from suap.models import employee 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 = 'employee' authentication = basicauthentication()
1/ need workjourneyresource
rather workjourney
when define relation in ressoure.py
2/ allow null value, add together null=true, blank=true
here code fixed:
class employeeresource(modelresource): journey = fields.foreignkey(workjourneyresource, 'work_journey', null=true, blank=true) ....
django rest tastypie
No comments:
Post a Comment