From b2e7e18f8ac041b2b0ba2b1ee14eedb0b90ef431 Mon Sep 17 00:00:00 2001 From: chenzuoqing Date: Wed, 1 Dec 2021 11:47:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=BF=A1=E6=81=AF=E6=97=B6?= =?UTF-8?q?=E6=9C=BA=E5=99=A8=E5=AF=B9=E8=B1=A1=E4=BF=9D=E5=AD=98=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E5=90=8D=E7=A7=B0=E5=88=B0tags?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/project/views.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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: