we did it bois, we enter in the user id for each one
This commit is contained in:
BIN
website/upload/__pycache__/__init__.cpython-38.pyc
Normal file
BIN
website/upload/__pycache__/__init__.cpython-38.pyc
Normal file
Binary file not shown.
BIN
website/upload/__pycache__/admin.cpython-38.pyc
Normal file
BIN
website/upload/__pycache__/admin.cpython-38.pyc
Normal file
Binary file not shown.
BIN
website/upload/__pycache__/forms.cpython-38.pyc
Normal file
BIN
website/upload/__pycache__/forms.cpython-38.pyc
Normal file
Binary file not shown.
BIN
website/upload/__pycache__/models.cpython-38.pyc
Normal file
BIN
website/upload/__pycache__/models.cpython-38.pyc
Normal file
Binary file not shown.
BIN
website/upload/__pycache__/validators.cpython-38.pyc
Normal file
BIN
website/upload/__pycache__/validators.cpython-38.pyc
Normal file
Binary file not shown.
BIN
website/upload/__pycache__/views.cpython-38.pyc
Normal file
BIN
website/upload/__pycache__/views.cpython-38.pyc
Normal file
Binary file not shown.
@ -7,7 +7,7 @@ class ImageForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Image
|
||||
fields = ('title', 'image')
|
||||
|
||||
|
||||
class VideoForm(forms.ModelForm):
|
||||
"""Form for the image model"""
|
||||
class Meta:
|
||||
|
32
website/upload/migrations/0006_auto_20210218_0008.py
Normal file
32
website/upload/migrations/0006_auto_20210218_0008.py
Normal file
@ -0,0 +1,32 @@
|
||||
# Generated by Django 3.1.6 on 2021-02-17 22:08
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
import upload.validators
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
('upload', '0005_videos'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='image',
|
||||
name='user',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='image',
|
||||
name='image',
|
||||
field=models.ImageField(upload_to='images/', validators=[upload.validators.imageValidate]),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='videos',
|
||||
name='video',
|
||||
field=models.FileField(upload_to='videos/', validators=[upload.validators.videoValidate]),
|
||||
),
|
||||
]
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
website/upload/migrations/__pycache__/0005_videos.cpython-38.pyc
Normal file
BIN
website/upload/migrations/__pycache__/0005_videos.cpython-38.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
website/upload/migrations/__pycache__/__init__.cpython-38.pyc
Normal file
BIN
website/upload/migrations/__pycache__/__init__.cpython-38.pyc
Normal file
Binary file not shown.
@ -1,5 +1,6 @@
|
||||
from django.db import models
|
||||
from .validators import videoValidate, imageValidate
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
# def user_directory._path(instance, filename):
|
||||
# print(request.user.id)
|
||||
@ -10,18 +11,19 @@ from .validators import videoValidate, imageValidate
|
||||
|
||||
class Image(models.Model):
|
||||
title = models.CharField(max_length=200)
|
||||
image = models.ImageField(upload_to=f"images/{upload_to}",validators=[imageValidate])
|
||||
|
||||
image = models.ImageField(upload_to=f"images/",validators=[imageValidate])
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE, blank=True, null=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
|
||||
|
||||
class Videos(models.Model):
|
||||
title = models.CharField(max_length=100)
|
||||
video = models.FileField(upload_to=f'videos/', validators=[videoValidate])
|
||||
|
||||
|
||||
class Meta:
|
||||
verbose_name = 'video'
|
||||
verbose_name_plural = 'videos'
|
||||
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
|
@ -22,14 +22,17 @@ def uploadContent(request):
|
||||
|
||||
def imageUpload(request):
|
||||
"""Process images uploaded by users"""
|
||||
|
||||
print(request.user.id)
|
||||
if request.method == 'POST':
|
||||
form = ImageForm(request.POST, request.FILES)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
# Get the current instance object to display in the template
|
||||
img_obj = form.instance
|
||||
img_obj.user = request.user
|
||||
form.save()
|
||||
return render(request, 'uploadImage.html', {'form': form, 'img_obj': img_obj})
|
||||
|
||||
|
||||
else:
|
||||
form = ImageForm()
|
||||
return render(request, 'uploadImage.html', {'form': form})
|
||||
@ -42,8 +45,7 @@ def videoUpload(request):
|
||||
form.save()
|
||||
img_obj = form.instance
|
||||
return render(request, 'uploadVideo.html', {'form': form, 'img_obj': img_obj})
|
||||
|
||||
|
||||
else:
|
||||
form = VideoForm()
|
||||
return render(request, 'uploadVideo.html', {'form': form})
|
||||
|
||||
|
Reference in New Issue
Block a user