def default(self, obj):
        if hasattr(obj, '__iter__'):
            # mainly for queryset serialization
            return list(obj)
        if isinstance(obj, Package):
            data = {attr: getattr(obj, attr) for attr in self.pkg_attributes}
            for attr in self.pkg_list_attributes:
                data[attr] = getattr(obj, attr).all()
            all_deps = obj.depends.all()
            for (deptype, name) in DEPENDENCY_TYPES:
                data[name] = all_deps.filter(deptype=deptype)
            return data
        if isinstance(obj, PackageFile):
            filename = obj.filename or ''
            return obj.directory + filename
        if isinstance(obj, (Repo, Arch)):
            return obj.name.lower()
        if isinstance(obj, (PackageGroup, License)):
            return obj.name
        if isinstance(obj, (Depend, Conflict, Provision, Replacement)):
            return str(obj)
        elif isinstance(obj, User):
            return obj.username
        elif isinstance(obj, TodolistPackage):
            data = self.default(obj.pkg)
            for attr in self.todolistpackage_attributes:
                data[attr] = getattr(obj, attr)
            return data
        return super(PackageJSONEncoder, self).default(obj)