diff --git a/src/project/views.py b/src/project/views.py index a16a2ba..2b256d6 100644 --- a/src/project/views.py +++ b/src/project/views.py @@ -111,8 +111,13 @@ class ServerSyncView(CreateMixin): try: if not host: - hostObj, _ = Host.get_or_create( - public_ip=ip, defaults=dict(public_ip=ip, created=datetime.datetime.now())) + proj = self.project.fullname() + hostObj, created = Host.get_or_create( + public_ip=ip, defaults=dict(public_ip=ip, tags=[proj], created=datetime.datetime.now())) + # 项目写入机器的tags + if not created and proj not in hostObj.tags: + hostObj.tags.append(proj) + hostObj.save() host = hostObj.id hosts[ip] = hostObj.id if not channel: