Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
kszkepzes-backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
JetBrains YouTrack
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
KSZK
DevTeam
kszkepzes
old
kszkepzes-backend
Commits
e5e012e6
Commit
e5e012e6
authored
5 years ago
by
Rafael László
Browse files
Options
Downloads
Patches
Plain Diff
delete images from file system
parent
6fb4b661
No related branches found
No related tags found
1 merge request
!2
Dev
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/account/views.py
+1
-0
1 addition, 0 deletions
src/account/views.py
src/images/models.py
+10
-0
10 additions, 0 deletions
src/images/models.py
src/kszkepzes/settings/base.py
+1
-1
1 addition, 1 deletion
src/kszkepzes/settings/base.py
src/mentors/models.py
+10
-0
10 additions, 0 deletions
src/mentors/models.py
with
22 additions
and
1 deletion
src/account/views.py
+
1
−
0
View file @
e5e012e6
...
@@ -3,6 +3,7 @@ from rest_framework import permissions
...
@@ -3,6 +3,7 @@ from rest_framework import permissions
from
rest_framework.response
import
Response
from
rest_framework.response
import
Response
from
rest_framework.decorators
import
action
from
rest_framework.decorators
import
action
from
common.permissions
import
IsSafeOrPatch
from
common.permissions
import
IsSafeOrPatch
from
django.db.models
import
Sum
from
.
import
models
from
.
import
models
from
.
import
serializers
from
.
import
serializers
...
...
This diff is collapsed.
Click to expand it.
src/images/models.py
+
10
−
0
View file @
e5e012e6
import
os
from
django.db
import
models
from
django.db
import
models
from
django.dispatch
import
receiver
class
Image
(
models
.
Model
):
class
Image
(
models
.
Model
):
...
@@ -8,3 +11,10 @@ class Image(models.Model):
...
@@ -8,3 +11,10 @@ class Image(models.Model):
def
__str__
(
self
):
def
__str__
(
self
):
return
str
(
self
.
id
)
return
str
(
self
.
id
)
# Deletes file from filesystem when File object is deleted.
@receiver
(
models
.
signals
.
post_delete
,
sender
=
Image
)
def
auto_delete_image_on_delete
(
sender
,
instance
,
**
kwargs
):
if
instance
.
image
:
if
os
.
path
.
isfile
(
instance
.
image
.
path
):
os
.
remove
(
instance
.
image
.
path
)
This diff is collapsed.
Click to expand it.
src/kszkepzes/settings/base.py
+
1
−
1
View file @
e5e012e6
This diff is collapsed.
Click to expand it.
src/mentors/models.py
+
10
−
0
View file @
e5e012e6
import
os
from
django.db
import
models
from
django.db
import
models
from
account.models
import
Profile
from
account.models
import
Profile
from
django.dispatch
import
receiver
class
Mentor
(
models
.
Model
):
class
Mentor
(
models
.
Model
):
...
@@ -16,3 +19,10 @@ class Mentor(models.Model):
...
@@ -16,3 +19,10 @@ class Mentor(models.Model):
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
name
return
self
.
name
# Deletes file from filesystem when File object is deleted.
@receiver
(
models
.
signals
.
post_delete
,
sender
=
Mentor
)
def
auto_delete_image_on_delete
(
sender
,
instance
,
**
kwargs
):
if
instance
.
image
:
if
os
.
path
.
isfile
(
instance
.
image
.
path
):
os
.
remove
(
instance
.
image
.
path
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment