fix EmployeeBackSerializers
This commit is contained in:
parent
54c3e452e2
commit
30e25c2da0
|
|
@ -186,16 +186,19 @@ class EmployeeBackSerializers(serializers.ModelSerializer):
|
|||
"""Get last list actual public_mark"""
|
||||
qs = obj.establishmentemployee_set.actual().order_by('-from_date')\
|
||||
.values('establishment__public_mark').first()
|
||||
return qs['establishment__public_mark']
|
||||
return qs['establishment__public_mark'] if qs else None
|
||||
|
||||
|
||||
def get_positions(self, obj):
|
||||
"""Get last list actual positions"""
|
||||
est_id = obj.establishmentemployee_set.actual().\
|
||||
order_by('-from_date').first().establishment_id
|
||||
order_by('-from_date').first()
|
||||
|
||||
if not est_id:
|
||||
return None
|
||||
|
||||
qs = obj.establishmentemployee_set.actual()\
|
||||
.filter(establishment_id=est_id)\
|
||||
.filter(establishment_id=est_id.establishment_id)\
|
||||
.prefetch_related('position').values('position')
|
||||
|
||||
positions = models.Position.objects.filter(id__in=[q['position'] for q in qs])
|
||||
|
|
@ -205,11 +208,14 @@ class EmployeeBackSerializers(serializers.ModelSerializer):
|
|||
def get_establishment(self, obj):
|
||||
"""Get last actual establishment"""
|
||||
est = obj.establishmentemployee_set.actual().order_by('-from_date')\
|
||||
.first().establishment
|
||||
.first()
|
||||
|
||||
if not est:
|
||||
return None
|
||||
|
||||
return {
|
||||
"id": est.id,
|
||||
"slug": est.slug
|
||||
"id": est.establishment.id,
|
||||
"slug": est.establishment.slug
|
||||
}
|
||||
|
||||
class Meta:
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user