Skip to content

Commit

Permalink
api updates to add update counts
Browse files Browse the repository at this point in the history
  • Loading branch information
furlongm committed Feb 14, 2021
1 parent 31627fe commit c9f29f1
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion hosts/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,21 @@


class HostSerializer(serializers.HyperlinkedModelSerializer):
bugfix_update_count = serializers.SerializerMethodField()
security_update_count = serializers.SerializerMethodField()

class Meta(object):
model = Host
fields = ('id', 'hostname', 'ipaddress', 'reversedns', 'check_dns',
'os', 'kernel', 'arch', 'domain', 'lastreport', 'repos',
'updates', 'reboot_required', 'host_repos_only', 'tags',
'updated_at')
'updated_at', 'bugfix_update_count', 'security_update_count')

def get_bugfix_update_count(self, obj):
return len([u for u in obj.updates.all() if not u.security])

def get_security_update_count(self, obj):
return len([u for u in obj.updates.all() if u.security])


class HostRepoSerializer(serializers.HyperlinkedModelSerializer):
Expand Down

0 comments on commit c9f29f1

Please sign in to comment.