we did it bois, we enter in the user id for each one

This commit is contained in:
Yamozha 2021-02-18 00:31:54 +02:00
parent 322047b51b
commit a62ccb389d
35 changed files with 48 additions and 12 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 466 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 466 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 466 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 466 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 772 KiB

View File

@ -4,13 +4,13 @@
{% block content %}
{% if user.is_authenticated %}
Hi {{ user.username }}!<br>
Hi {{ user.username }} {{ user.id }}!<br>
<form method="post" enctype="multipart/form-data">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Upload</button>
</form>
{% if img_obj %}
<h3>Succesfully uploaded : {{img_obj.title}}</h3>
<img src="{{ img_obj.image.url}}" alt="connect" style="max-height:300px">

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -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:

View 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]),
),
]

View File

@ -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

View File

@ -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})

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.