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"""
|
"""Get last list actual public_mark"""
|
||||||
qs = obj.establishmentemployee_set.actual().order_by('-from_date')\
|
qs = obj.establishmentemployee_set.actual().order_by('-from_date')\
|
||||||
.values('establishment__public_mark').first()
|
.values('establishment__public_mark').first()
|
||||||
return qs['establishment__public_mark']
|
return qs['establishment__public_mark'] if qs else None
|
||||||
|
|
||||||
|
|
||||||
def get_positions(self, obj):
|
def get_positions(self, obj):
|
||||||
"""Get last list actual positions"""
|
"""Get last list actual positions"""
|
||||||
est_id = obj.establishmentemployee_set.actual().\
|
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()\
|
qs = obj.establishmentemployee_set.actual()\
|
||||||
.filter(establishment_id=est_id)\
|
.filter(establishment_id=est_id.establishment_id)\
|
||||||
.prefetch_related('position').values('position')
|
.prefetch_related('position').values('position')
|
||||||
|
|
||||||
positions = models.Position.objects.filter(id__in=[q['position'] for q in qs])
|
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):
|
def get_establishment(self, obj):
|
||||||
"""Get last actual establishment"""
|
"""Get last actual establishment"""
|
||||||
est = obj.establishmentemployee_set.actual().order_by('-from_date')\
|
est = obj.establishmentemployee_set.actual().order_by('-from_date')\
|
||||||
.first().establishment
|
.first()
|
||||||
|
|
||||||
|
if not est:
|
||||||
|
return None
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"id": est.id,
|
"id": est.establishment.id,
|
||||||
"slug": est.slug
|
"slug": est.establishment.slug
|
||||||
}
|
}
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user