Add intranet app
This commit is contained in:
parent
c96bd0d0db
commit
9773957baf
11 changed files with 167 additions and 1 deletions
25
intranet/admin.py
Normal file
25
intranet/admin.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import os
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib import admin
|
||||
|
||||
from intranet.models import IntranetDoc
|
||||
|
||||
|
||||
@admin.register(IntranetDoc)
|
||||
class IntranetDocAdmin(admin.ModelAdmin):
|
||||
list_display = ('__str__', 'module', 'authorization')
|
||||
|
||||
def save_model(self, request, obj, form, change):
|
||||
searched_file = 'intranet/{0}'.format(form.cleaned_data['doc'])
|
||||
try:
|
||||
doc = IntranetDoc.objects.get(doc=searched_file)
|
||||
form.save()
|
||||
# Override previous file
|
||||
filename = os.path.join(settings.MEDIA_ROOT, searched_file)
|
||||
file = request.FILES['doc']
|
||||
with open(filename, 'wb+') as destination:
|
||||
for chunk in file.chunks():
|
||||
destination.write(chunk)
|
||||
except IntranetDoc.DoesNotExist:
|
||||
super().save_model(request, obj, form, change)
|
||||
Loading…
Add table
Add a link
Reference in a new issue