Skip to content
This repository has been archived by the owner on Mar 17, 2024. It is now read-only.

Commit

Permalink
Do not delete Model if the corresponsing Project is removed; set stat…
Browse files Browse the repository at this point in the history
…us to Archived
  • Loading branch information
dstoyanova committed May 12, 2020
1 parent 9b06026 commit e12c0d5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 7 additions & 1 deletion components/studio/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ class Model(models.Model):

CREATED = 'CR'
DEPLOYED = 'DP'
ARCHIVED = 'AR'
STATUS = [
(CREATED, 'Created'),
(DEPLOYED, 'Deployed'),
(ARCHIVED, 'Archived'),
]
uid = models.CharField(max_length=255)
name = models.CharField(max_length=255)
Expand All @@ -27,7 +29,11 @@ class Model(models.Model):
resource = models.URLField(max_length=2048, null=True, blank=True)
url = models.URLField(max_length=512, null=True, blank=True)
uploaded_at = models.DateTimeField(auto_now_add=True)
project = models.ForeignKey('projects.Project', on_delete=models.CASCADE, related_name='model_owner')
project = models.ForeignKey(
'projects.Project',
on_delete=models.SET_NULL,
related_name='model_owner',
null=True)
status = models.CharField(max_length=2, choices=STATUS, default=CREATED)
tag = models.CharField(max_length=10, default='latest')

Expand Down
6 changes: 6 additions & 0 deletions components/studio/projects/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import markdown
from .forms import TransferProjectOwnershipForm
from django.db.models import Q
from models.models import Model

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -172,6 +173,11 @@ def delete(request, user, project_slug):

print("PROJECT RESOURCES DELETED SUCCESFULLY!")

models = Model.objects.filter(project=project)
for model in models:
model.status = 'AR'
model.save()

project.delete()

return HttpResponseRedirect(next_page, {'message': 'Deleted project successfully.'})
Expand Down

0 comments on commit e12c0d5

Please sign in to comment.