Added the primal mechanic in which user balance exists(VERY ROUGH)
This commit is contained in:
parent
83fecc9d6f
commit
3e37c1ca20
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 688 KiB |
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.
16
reValuate/templates/getBalance.html
Normal file
16
reValuate/templates/getBalance.html
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<!-- templates/home.html -->
|
||||||
|
{% extends 'base.html' %}
|
||||||
|
|
||||||
|
{% block title %}Home{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
{% if user.is_authenticated %}
|
||||||
|
Hi {{ user.username }}!
|
||||||
|
{{ userBalance }}
|
||||||
|
{% else %}
|
||||||
|
<p>You are not logged in</p>
|
||||||
|
<a href="{% url 'login' %}">Log In</a>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% endblock %}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,21 +0,0 @@
|
|||||||
# Generated by Django 3.1.6 on 2021-02-09 15:56
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
initial = True
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.CreateModel(
|
|
||||||
name='Image',
|
|
||||||
fields=[
|
|
||||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
|
||||||
('image', models.ImageField(blank=True, upload_to='static/%Y/%m/%d/')),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
]
|
|
@ -1,18 +0,0 @@
|
|||||||
# Generated by Django 3.1.6 on 2021-02-09 16:03
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('upload', '0001_initial'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='image',
|
|
||||||
name='image',
|
|
||||||
field=models.FileField(upload_to='../static/%Y/%m/%d/'),
|
|
||||||
),
|
|
||||||
]
|
|
@ -1,18 +0,0 @@
|
|||||||
# Generated by Django 3.1.6 on 2021-02-09 16:06
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('upload', '0002_auto_20210209_1803'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='image',
|
|
||||||
name='image',
|
|
||||||
field=models.FileField(upload_to='static/'),
|
|
||||||
),
|
|
||||||
]
|
|
@ -1,25 +0,0 @@
|
|||||||
# Generated by Django 3.1.6 on 2021-02-16 22:41
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
import django.utils.timezone
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('upload', '0003_auto_20210209_1806'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AddField(
|
|
||||||
model_name='image',
|
|
||||||
name='title',
|
|
||||||
field=models.CharField(default=django.utils.timezone.now, max_length=200),
|
|
||||||
preserve_default=False,
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='image',
|
|
||||||
name='image',
|
|
||||||
field=models.ImageField(upload_to='images'),
|
|
||||||
),
|
|
||||||
]
|
|
@ -1,25 +0,0 @@
|
|||||||
# Generated by Django 3.1.6 on 2021-02-16 22:52
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('upload', '0004_auto_20210217_0041'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.CreateModel(
|
|
||||||
name='Videos',
|
|
||||||
fields=[
|
|
||||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
|
||||||
('title', models.CharField(max_length=100)),
|
|
||||||
('video', models.FileField(upload_to='videos/')),
|
|
||||||
],
|
|
||||||
options={
|
|
||||||
'verbose_name': 'video',
|
|
||||||
'verbose_name_plural': 'videos',
|
|
||||||
},
|
|
||||||
),
|
|
||||||
]
|
|
@ -1,32 +0,0 @@
|
|||||||
# 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]),
|
|
||||||
),
|
|
||||||
]
|
|
@ -1,19 +0,0 @@
|
|||||||
# Generated by Django 3.1.6 on 2021-02-19 12:19
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
import upload.validators
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('upload', '0006_auto_20210218_0008'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='image',
|
|
||||||
name='image',
|
|
||||||
field=models.ImageField(upload_to='images/<django.db.models.fields.related.ForeignKey>', validators=[upload.validators.imageValidate]),
|
|
||||||
),
|
|
||||||
]
|
|
@ -1,19 +0,0 @@
|
|||||||
# Generated by Django 3.1.6 on 2021-02-19 12:24
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
import upload.validators
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('upload', '0007_auto_20210219_1419'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='image',
|
|
||||||
name='image',
|
|
||||||
field=models.ImageField(upload_to='images/None/', validators=[upload.validators.imageValidate]),
|
|
||||||
),
|
|
||||||
]
|
|
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.
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.
@ -9,21 +9,25 @@ from django.contrib.auth.models import User
|
|||||||
# I want to be able to store each and every user's files in a separate folder, based on their id
|
# I want to be able to store each and every user's files in a separate folder, based on their id
|
||||||
# I CANT GET A FUCKING LOGGED IN USER ID FROM THE MODELS THINGY IM FUCKING PISSED
|
# I CANT GET A FUCKING LOGGED IN USER ID FROM THE MODELS THINGY IM FUCKING PISSED
|
||||||
|
|
||||||
def user_directory_path(instance, filename):
|
def imagesPath(instance, filename):
|
||||||
# file will be uploaded to MEDIA_ROOT/user_<id>/<filename>
|
# file will be uploaded to MEDIA_ROOT/user_<id>/<filename>
|
||||||
return 'images/{0}/{1}'.format(instance.user.id, filename)
|
return 'images/{0}/{1}'.format(instance.user.id, filename)
|
||||||
|
|
||||||
|
def videosPath(instance,filename):
|
||||||
|
return f"videos/{instance.user.id}/{filename}"
|
||||||
|
|
||||||
class Image(models.Model):
|
class Image(models.Model):
|
||||||
user = models.ForeignKey(User, on_delete=models.CASCADE, blank=True, null=True)
|
user = models.OneToOneField(User, on_delete=models.CASCADE, blank=True, null=True)
|
||||||
title = models.CharField(max_length=200)
|
title = models.CharField(max_length=200)
|
||||||
image = models.ImageField(upload_to=user_directory_path,validators=[imageValidate])
|
image = models.ImageField(upload_to=imagesPath,validators=[imageValidate])
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.title
|
return self.title
|
||||||
|
|
||||||
class Videos(models.Model):
|
class Videos(models.Model):
|
||||||
|
user = models.OneToOneField(User, on_delete=models.CASCADE, blank=True, null=True)
|
||||||
title = models.CharField(max_length=100)
|
title = models.CharField(max_length=100)
|
||||||
video = models.FileField(upload_to=f'videos/', validators=[videoValidate])
|
video = models.FileField(upload_to=videosPath, validators=[videoValidate])
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = 'video'
|
verbose_name = 'video'
|
||||||
|
@ -3,7 +3,7 @@ import os.path
|
|||||||
import os
|
import os
|
||||||
from .forms import ImageForm, VideoForm
|
from .forms import ImageForm, VideoForm
|
||||||
from django.core.files.storage import FileSystemStorage
|
from django.core.files.storage import FileSystemStorage
|
||||||
from .models import Image
|
from .models import Image, Videos
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
def uploadContent(request):
|
def uploadContent(request):
|
||||||
@ -29,7 +29,6 @@ def imageUpload(request):
|
|||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
form = ImageForm(request.POST, request.FILES)
|
form = ImageForm(request.POST, request.FILES)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
# Get the current instance object to display in the template
|
|
||||||
userIdModel = Image.objects.filter(user=request.user.id)
|
userIdModel = Image.objects.filter(user=request.user.id)
|
||||||
img_obj = form.instance
|
img_obj = form.instance
|
||||||
img_obj.user = request.user
|
img_obj.user = request.user
|
||||||
@ -45,8 +44,10 @@ def videoUpload(request):
|
|||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
form = VideoForm(request.POST, request.FILES)
|
form = VideoForm(request.POST, request.FILES)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
form.save()
|
userIdModel = Videos.objects.filter(user=request.user.id)
|
||||||
img_obj = form.instance
|
img_obj = form.instance
|
||||||
|
img_obj.user = request.user
|
||||||
|
form.save()
|
||||||
return render(request, 'uploadVideo.html', {'form': form, 'img_obj': img_obj})
|
return render(request, 'uploadVideo.html', {'form': form, 'img_obj': img_obj})
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
25
reValuate/users/migrations/0001_initial.py
Normal file
25
reValuate/users/migrations/0001_initial.py
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
# Generated by Django 3.1.6 on 2021-02-20 19:15
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Balance',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('balance', models.IntegerField(default=0)),
|
||||||
|
('user', models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
18
reValuate/users/migrations/0002_auto_20210220_2131.py
Normal file
18
reValuate/users/migrations/0002_auto_20210220_2131.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 3.1.6 on 2021-02-20 19:31
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('users', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name='balance',
|
||||||
|
old_name='balance',
|
||||||
|
new_name='balanceValue',
|
||||||
|
),
|
||||||
|
]
|
18
reValuate/users/migrations/0003_auto_20210220_2142.py
Normal file
18
reValuate/users/migrations/0003_auto_20210220_2142.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 3.1.6 on 2021-02-20 19:42
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('users', '0002_auto_20210220_2131'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='balance',
|
||||||
|
name='user',
|
||||||
|
field=models.CharField(max_length=120),
|
||||||
|
),
|
||||||
|
]
|
21
reValuate/users/migrations/0004_auto_20210220_2143.py
Normal file
21
reValuate/users/migrations/0004_auto_20210220_2143.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
# Generated by Django 3.1.6 on 2021-02-20 19:43
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||||
|
('users', '0003_auto_20210220_2142'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='balance',
|
||||||
|
name='user',
|
||||||
|
field=models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
|
||||||
|
),
|
||||||
|
]
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
reValuate/users/migrations/__pycache__/__init__.cpython-36.pyc
Normal file
BIN
reValuate/users/migrations/__pycache__/__init__.cpython-36.pyc
Normal file
Binary file not shown.
@ -1,3 +1,11 @@
|
|||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
# Create your models here.
|
|
||||||
|
class Balance(models.Model):
|
||||||
|
user = models.OneToOneField(User, on_delete=models.CASCADE, blank=True, null=True)
|
||||||
|
balanceValue = models.IntegerField(default=0)
|
||||||
|
|
||||||
|
def balanceReturn(self):
|
||||||
|
print(f"Pederas 123 {self.balance}")
|
||||||
|
return self.balance
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
from django.contrib.auth.forms import UserCreationForm
|
from django.contrib.auth.forms import UserCreationForm
|
||||||
from django.urls import reverse_lazy
|
from django.urls import reverse_lazy
|
||||||
from django.views import generic
|
from django.views import generic
|
||||||
|
from .models import Balance
|
||||||
|
from django.shortcuts import render, redirect
|
||||||
|
|
||||||
# need to make oauth facebook login
|
# need to make oauth facebook login
|
||||||
class SignUpView(generic.CreateView):
|
class SignUpView(generic.CreateView):
|
||||||
@ -9,3 +10,18 @@ class SignUpView(generic.CreateView):
|
|||||||
success_url = reverse_lazy('login')
|
success_url = reverse_lazy('login')
|
||||||
template_name = 'registration/signup.html'
|
template_name = 'registration/signup.html'
|
||||||
|
|
||||||
|
def addToBalance(request):
|
||||||
|
testVar = 5
|
||||||
|
balAdd = Balance.objects.create(balanceValue=testVar, user=request.user.id)
|
||||||
|
balAdd.save()
|
||||||
|
print(balAdd)
|
||||||
|
|
||||||
|
return render(request,"getBalance.html", {"userBalance":balAdd})
|
||||||
|
|
||||||
|
def getBalance(request):
|
||||||
|
balObject = Balance.objects.filter(user=request.user.id)
|
||||||
|
print(dir(balObject))
|
||||||
|
userBalance = balObject.values
|
||||||
|
|
||||||
|
return render(request,"getBalance.html", {"userBalance":userBalance} )
|
||||||
|
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -21,7 +21,7 @@ from django.conf.urls.static import static
|
|||||||
from django.contrib.auth import views
|
from django.contrib.auth import views
|
||||||
from django.views.generic.base import TemplateView
|
from django.views.generic.base import TemplateView
|
||||||
from upload.views import uploadContent, imageUpload, videoUpload, viewMedia
|
from upload.views import uploadContent, imageUpload, videoUpload, viewMedia
|
||||||
|
from users.views import getBalance, addToBalance
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("", homePage, name='home'),
|
path("", homePage, name='home'),
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
@ -31,6 +31,8 @@ urlpatterns = [
|
|||||||
path("upload_image/", imageUpload, name="Image"),
|
path("upload_image/", imageUpload, name="Image"),
|
||||||
path("upload_video/", videoUpload, name="Video"),
|
path("upload_video/", videoUpload, name="Video"),
|
||||||
path("view_media/", viewMedia, name="All Media"),
|
path("view_media/", viewMedia, name="All Media"),
|
||||||
|
path("get_balance/",getBalance, name="Balance" ),
|
||||||
|
path("add_balance/", addToBalance, name="Add")
|
||||||
]
|
]
|
||||||
if settings.DEBUG:
|
if settings.DEBUG:
|
||||||
urlpatterns += static(settings.MEDIA_URL,
|
urlpatterns += static(settings.MEDIA_URL,
|
||||||
|
Reference in New Issue
Block a user