mirror of
https://github.com/lemeow125/Ivy-Backend.git
synced 2024-11-16 22:29:25 +08:00
Added products model
This commit is contained in:
parent
62237c9a3c
commit
d98c88482d
14 changed files with 98 additions and 3 deletions
1
Pipfile
1
Pipfile
|
@ -8,6 +8,7 @@ django = "*"
|
|||
djangorestframework = "*"
|
||||
djoser = "*"
|
||||
djangorestframework-simplejwt = "*"
|
||||
django-cors-headers = "*"
|
||||
|
||||
[dev-packages]
|
||||
autopep8 = "*"
|
||||
|
|
10
Pipfile.lock
generated
10
Pipfile.lock
generated
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"_meta": {
|
||||
"hash": {
|
||||
"sha256": "309b0b7b7b2f3dce9f8501a57dac5257ba3cca7d8e01cfc7284aa6c48279b23b"
|
||||
"sha256": "24c6a4fe52c048f750d36c10e0e1e0fd578de1b2455b1dd082ef830c272e461a"
|
||||
},
|
||||
"pipfile-spec": 6,
|
||||
"requires": {
|
||||
|
@ -253,6 +253,14 @@
|
|||
"index": "pypi",
|
||||
"version": "==4.1.7"
|
||||
},
|
||||
"django-cors-headers": {
|
||||
"hashes": [
|
||||
"sha256:5fbd58a6fb4119d975754b2bc090f35ec160a8373f276612c675b00e8a138739",
|
||||
"sha256:684180013cc7277bdd8702b80a3c5a4b3fcae4abb2bf134dceb9f5dfe300228e"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==3.14.0"
|
||||
},
|
||||
"django-templated-mail": {
|
||||
"hashes": [
|
||||
"sha256:8db807effebb42a532622e2d142dfd453dafcd0d7794c4c3332acb90656315f9",
|
||||
|
|
|
@ -2,5 +2,6 @@ from django.contrib import admin
|
|||
from django.urls import path, include
|
||||
|
||||
urlpatterns = [
|
||||
path('accounts/', include('accounts.urls'))
|
||||
path('', include('products.urls')),
|
||||
path('accounts/', include('accounts.urls')),
|
||||
]
|
||||
|
|
|
@ -41,6 +41,7 @@ INSTALLED_APPS = [
|
|||
'rest_framework.authtoken',
|
||||
'djoser',
|
||||
'corsheaders',
|
||||
'products',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
|
@ -110,7 +111,7 @@ AUTH_PASSWORD_VALIDATORS = [
|
|||
|
||||
LANGUAGE_CODE = 'en-us'
|
||||
|
||||
TIME_ZONE = 'UTC'
|
||||
TIME_ZONE = 'Asia/Manila'
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
|
@ -146,4 +147,5 @@ EMAIL_PORT = '2525'
|
|||
|
||||
CORS_ALLOWED_ORIGINS = [
|
||||
"http://localhost:3000",
|
||||
"http://localhost:8000",
|
||||
]
|
||||
|
|
0
ivy/products/__init__.py
Normal file
0
ivy/products/__init__.py
Normal file
3
ivy/products/admin.py
Normal file
3
ivy/products/admin.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
6
ivy/products/apps.py
Normal file
6
ivy/products/apps.py
Normal file
|
@ -0,0 +1,6 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class ProductsConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'products'
|
24
ivy/products/migrations/0001_initial.py
Normal file
24
ivy/products/migrations/0001_initial.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
# Generated by Django 4.1.7 on 2023-03-05 13:54
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.utils.timezone
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Product',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=20)),
|
||||
('quantity', models.IntegerField(default=0)),
|
||||
('date_added', models.DateTimeField(default=django.utils.timezone.now, editable=False)),
|
||||
],
|
||||
),
|
||||
]
|
0
ivy/products/migrations/__init__.py
Normal file
0
ivy/products/migrations/__init__.py
Normal file
12
ivy/products/models.py
Normal file
12
ivy/products/models.py
Normal file
|
@ -0,0 +1,12 @@
|
|||
from django.db import models
|
||||
from django.utils.timezone import now
|
||||
# Create your models here.
|
||||
|
||||
|
||||
class Product(models.Model):
|
||||
name = models.CharField(max_length=20)
|
||||
quantity = models.IntegerField(default=0)
|
||||
date_added = models.DateTimeField(default=now, editable=False)
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
12
ivy/products/serializers.py
Normal file
12
ivy/products/serializers.py
Normal file
|
@ -0,0 +1,12 @@
|
|||
from rest_framework import serializers
|
||||
from .models import Product
|
||||
|
||||
|
||||
class ProductSerializer(serializers.HyperlinkedModelSerializer):
|
||||
date_added = serializers.DateTimeField(
|
||||
format="%d-%m-%Y %I:%M%p", read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = Product
|
||||
fields = ('name', 'quantity', 'date_added')
|
||||
read_only_fields = ('id', 'date_added')
|
3
ivy/products/tests.py
Normal file
3
ivy/products/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
13
ivy/products/urls.py
Normal file
13
ivy/products/urls.py
Normal file
|
@ -0,0 +1,13 @@
|
|||
from django.urls import include, path
|
||||
from rest_framework import routers
|
||||
from . import views
|
||||
|
||||
router = routers.DefaultRouter()
|
||||
router.register(r'products', views.ProductViewSet)
|
||||
|
||||
# Wire up our API using automatic URL routing.
|
||||
# Additionally, we include login URLs for the browsable API.
|
||||
urlpatterns = [
|
||||
path('', include(router.urls)),
|
||||
|
||||
]
|
10
ivy/products/views.py
Normal file
10
ivy/products/views.py
Normal file
|
@ -0,0 +1,10 @@
|
|||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework import viewsets
|
||||
from .serializers import ProductSerializer
|
||||
from .models import Product
|
||||
|
||||
|
||||
class ProductViewSet(viewsets.ModelViewSet):
|
||||
permission_classes = [IsAuthenticated]
|
||||
serializer_class = ProductSerializer
|
||||
queryset = Product.objects.all()
|
Loading…
Reference in a new issue