В настоящее время я хочу создавать медиа-типы, которые являются общими и приватными. Для media shared все проекты могут просматривать медиа, в то время как для media private его может просматривать только определенный проект. Я не почему его не работает. Это мое кодирование
views.py
def CONprojectnewknowledgecenter(request, id):
project_dat = get_object_or_404(project_db, pk=id)
if request.method == 'GET':
all_format = Format.objects.all()
all_category = Category.objects.all()
all_mediatype = MediaType.objects.all()
return render(request, 'dashboard/CONprojectnewknowledgecenter.html',
{'all_format': all_format, 'all_category': all_category, 'all_mediatype': all_mediatype, 'project_dat': project_dat})
if request.method == 'POST':
print("Creating new Kc, format: ", request.POST.get('format_id'))
formatinstance = get_object_or_404(Format, pk=request.POST.get('format_id'))
print("Creating new Kc, category: ", request.POST.get('category_id'))
categorylist = get_object_or_404(Category, pk=request.POST.get('category_id'))
print("Creating new Kc, media type: ", request.POST.get('mediatype_id'))
mediatypes = get_object_or_404(MediaType, pk=request.POST.get('mediatype_id'))
kc_submission = Kc.objects.create()
image = None
try:
print("Checking for Kc Image ... ")
image = request.FILES['image']
except:
print("Error: No Kc Images Found. Revert to NULL value.")
finally:
print("Checking for Kc Filetype ... ")
if formatinstance.filetype == 'File':
print("Filetype:File")
if categorylist.category == 'Category':
print("Category selected")
if mediatypes.mediatype == 'Media':
print("Media Type selected")
try:
print("Checking for Kc Filesource ... ")
my_uploaded_file = request.FILES['inputmediafile']
except:
print("Error: No Kc Filesource Found. Redirecting back to input page.")
return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
inputmedia = my_uploaded_file.name
status = gcp("write", file_path="project/" + str(kc_submission.id) + "/" + inputmedia,
item=my_uploaded_file.read())
else:
print("Filetype:Link --- ", request.POST.get('inputmedialink'))
inputmedia = request.POST.get('inputmedialink') if request.POST.get('inputmedialink') else "https://www.youtube.com/"
kc_submission.__dict__.update(project_db_id=id, title=request.POST.get('title'), category_id=categorylist.id, mediatype_id=mediatypes.id,
date=request.POST.get('date'), format_id=formatinstance.id, image=image,
inputmedia=inputmedia)
kc_submission.save()
return HttpResponseRedirect(reverse('dashboard:CONprojectdetails', kwargs={'id': id}))
CONprojectnewknowledgecenter. html
<div class="form-group row">
<label class="col-sm-4 col-form-label">Media Type :</label>
<div class="col-md-6">
<select id="mediatype_id" name="mediatype_id" class="select2 form-control custom select"style="width: 100%; height:36px;" >
<option>Choose one</option>
<option value="1">Shared</option>
<option value="2">Private</option>
<option value="{{mediatype.name}}">{{mediatype.name}}</option>
</select>
</div>
</div>
projects / models.py
class Kc(models.Model):
project_db = models.ForeignKey(project_db, on_delete=models.CASCADE, related_name='kc_project',null=True)
# project_db = models.ForeignKey(project_db, on_delete=models.CASCADE, related_name='kc_project', null=True)
image = models.ImageField(upload_to='kcpic_folder/', blank=True, null=True)
title = models.TextField(blank=True)
date = models.TextField(blank=True)
format = models.ForeignKey(Format, on_delete=models.CASCADE, related_name='kc_format', null=True)
inputmedia = models.TextField(blank=True)
view = models.TextField(blank=True)
category = models.ForeignKey(Category, on_delete=models.CASCADE, related_name='kc_category', null=True)
mediatype = models.ForeignKey(MediaType, on_delete=models.CASCADE, related_name='kc_mediatype', null=True)
панель инструментов / models.py
class MediaType(models.Model):
mediatype = models.TextField(blank=True)