api creation

This commit is contained in:
Yamozha 2021-03-29 16:14:44 +03:00
parent 7e87b12812
commit 838a5d58d6
72 changed files with 73 additions and 25 deletions
reValuate
api
db.sqlite3
home/__pycache__
upload
users
website

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

3
reValuate/api/admin.py Normal file

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

5
reValuate/api/apps.py Normal file

@ -0,0 +1,5 @@
from django.apps import AppConfig
class ApiConfig(AppConfig):
name = 'api'

3
reValuate/api/models.py Normal file

@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

@ -0,0 +1,15 @@
from rest_framework import serializers
from users.models import Balance
from upload.models import Media
class BalanceSerializer(serializers.ModelSerializer):
class Meta:
model = Balance
fields = ("user", "balanceValue")
class ImageSerializer(serializers.ModelSerializer):
class Meta:
model = Media
fields = ("user", "image", "tokenized", "reason", "date", "managed_by")

3
reValuate/api/tests.py Normal file

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

15
reValuate/api/views.py Normal file

@ -0,0 +1,15 @@
from rest_framework import status, viewsets
from rest_framework.decorators import api_view
from rest_framework.response import Response
from users.models import Balance
from upload.models import Media
from .serializers import BalanceSerializer, ImageSerializer
class BalanceView(viewsets.ModelViewSet):
queryset = Balance.objects.all()
serializer_class = BalanceSerializer
class ImageView(viewsets.ModelViewSet):
queryset = Media.objects.all()
serializer_class = ImageSerializer

Binary file not shown.

@ -3,14 +3,6 @@ from .validators import videoValidate, imageValidate
from django.contrib.auth.models import User
from datetime import date
# def user_directory._path(instance, filename):
# print(request.user.id)
# return 'user_{0}/{1}'.format(instance.user.id, filename)
# Ok i got hella angry, so pleaSE fix this bullshit
# 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
def imagesPath(instance, filename):
# file will be uploaded to MEDIA_ROOT/user_<id>/<filename>
return '{0}/{1}'.format(instance.user.id, filename)
@ -33,16 +25,3 @@ class Media(models.Model):
verbose_name = 'image'
verbose_name_plural = 'images'
# class Videos(models.Model):
# user = models.ForeignKey(User, on_delete=models.CASCADE, blank=True, null=True)
# video = models.FileField(upload_to=videosPath, validators=[videoValidate])
# tokenized = models.BooleanField(blank=True, null=True, default=None, max_length=3)
# reason = models.CharField(max_length=120)
# date = models.DateField(default=date.today)
# time = models.TimeField(auto_now=True)
# class Meta:
# verbose_name = 'video'
# verbose_name_plural = 'videos'

Binary file not shown.

@ -48,7 +48,8 @@ INSTALLED_APPS = [
'users',
'upload',
'qr_code',
'rest_framework',
'rest_framework.authtoken',
]
MIDDLEWARE = [
@ -145,4 +146,18 @@ ALL_COINS = 1000000
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
os.environ["DJANGO_ALLOW_ASYNC_UNSAFE"] = "true"
os.environ["DJANGO_ALLOW_ASYNC_UNSAFE"] = "true"
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.IsAuthenticated',
],
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework.authentication.BasicAuthentication',
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.TokenAuthentication',
]
}

@ -16,15 +16,23 @@ Including another URLconf
from django.contrib import admin
from django.urls import path, include
from home.views import homePage
from rest_framework import routers, urls
from api.views import BalanceView, ImageView
from django.conf import settings
from django.conf.urls.static import static
from django.contrib.auth import views
from django.views.generic.base import TemplateView
from upload.views import uploadContent, imageUpload, viewMedia
from users.views import getBalance, addToBalance, adminView, removeBalance
router = routers.DefaultRouter()
router.register("balance", BalanceView)
router.register("images", ImageView)
urlpatterns = [
path("", homePage, name='home'),
path("users/", include('django.contrib.auth.urls')),
path('users/', include('users.urls')),
# path("upload/", uploadContent, name="Upload"),
@ -34,7 +42,9 @@ urlpatterns = [
path("get_balance/",getBalance, name="Balance" ),
path("add_balance/", addToBalance, name="Add"),
path("remove_balance/", removeBalance, name="Add"),
path("admin/", adminView, name="admin")
path("admin/", adminView, name="admin"),
path('api/', include(router.urls))
]
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL,