Skip to content
This repository was archived by the owner on Aug 16, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
venv/
Binary file added backend/mydjangoproject/db.sqlite3
Binary file not shown.
Empty file.
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.
3 changes: 3 additions & 0 deletions backend/mydjangoproject/firstapp/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions backend/mydjangoproject/firstapp/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class FirstappConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'firstapp'
17 changes: 17 additions & 0 deletions backend/mydjangoproject/firstapp/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from django import forms
from .models import Product
from django.contrib.auth.models import User

class f1(forms.ModelForm):
class Meta:
model = Product
fields = ["name", "description",'price',]
labels = {'name': 'Name', 'description': 'Description', 'price': 'Price'}
class lo(forms.Form):
username = forms.CharField(max_length=150,label='Username')
password = forms.CharField(max_length=40,widget=forms.PasswordInput,label='Password')

class re(forms.Form):
username = forms.CharField(max_length=150)
password = forms.CharField(max_length=40,widget=forms.PasswordInput)

23 changes: 23 additions & 0 deletions backend/mydjangoproject/firstapp/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.2.2 on 2023-07-01 10:47

from django.db import migrations, models


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=255)),
('description', models.CharField(max_length=500)),
('price', models.IntegerField()),
],
),
]
22 changes: 22 additions & 0 deletions backend/mydjangoproject/firstapp/migrations/0002_product_user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 4.2.2 on 2023-07-01 17:24

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),
('firstapp', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='product',
name='user',
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
preserve_default=False,
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Generated by Django 4.2.2 on 2023-07-06 20:42

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),
('firstapp', '0002_product_user'),
]

operations = [
migrations.AddField(
model_name='product',
name='availability',
field=models.CharField(default='Available', max_length=255),
),
migrations.AlterField(
model_name='product',
name='user',
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
),
migrations.CreateModel(
name='Sales',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
('description', models.CharField(max_length=500)),
('price', models.IntegerField()),
('dt', models.DateTimeField()),
('user', models.ForeignKey(default=1, on_delete=django.db.models.deletion.SET_DEFAULT, to=settings.AUTH_USER_MODEL)),
],
),
]
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
18 changes: 18 additions & 0 deletions backend/mydjangoproject/firstapp/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from django.db import models
from django.contrib.auth.models import User

# Create your models here.

class Product(models.Model):
user = models.ForeignKey(User,on_delete=models.CASCADE,default=14)
name = models.CharField(max_length=255)
description = models.CharField(max_length=500)
price = models.IntegerField()
availability = models.CharField(max_length=255,default='Available')

class Sales(models.Model):
user = models.ForeignKey(User,on_delete=models.SET_DEFAULT,default=14)
name = models.CharField(max_length=255)
description = models.CharField(max_length=500)
price = models.IntegerField()
dt = models.DateTimeField()
17 changes: 17 additions & 0 deletions backend/mydjangoproject/firstapp/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from rest_framework import serializers
from .models import Product
from django.contrib.auth.models import User

class ProductSerializer(serializers.ModelSerializer):
class Meta:
model = Product
fields =['id','name', 'description', 'price']

class UserCreateSerializer(serializers.ModelSerializer):
password = serializers.CharField(write_only = True, required = True, style={ "input_type": "password"})

class Meta:
model = User
fields = ['username','email','password']


Empty file.
16 changes: 16 additions & 0 deletions backend/mydjangoproject/firstapp/templates/first.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.3.1/dist/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<title>Document</title>
</head>

<body>
<h1>Welcome to mt first html page on Django</h1>
</body>

</html>
25 changes: 25 additions & 0 deletions backend/mydjangoproject/firstapp/templates/form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.3.1/dist/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<title>Document</title>
</head>

<body>
<h1>ADD A Product</h1>
<div>
<form method="post">
{% csrf_token %}
{{form.as_p}}
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
<hr>
<a href="/product"><button type="button" class="btn btn-primary">View All</button></a>
</body>

</html>
15 changes: 15 additions & 0 deletions backend/mydjangoproject/firstapp/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home</title>
</head>

<body>
<h1>Welcome To Devansh' Week 2 assignment</h1>
<h4><a href="product">Let's Start</a></h4>
</body>

</html>
51 changes: 51 additions & 0 deletions backend/mydjangoproject/firstapp/templates/products.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.3.1/dist/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<title>Document</title>
</head>

<body>
<h1>Products</h1>
{% if user.is_authenticated %}

<a href="/logout">Logout</a>

{%endif%}
{% if user.is_authenticated == False%}
<a href="/login">Login</a>
{% endif %}



<table class="table table-striped">
<tr>
<td>Name</td>
<td>Description</td>
<td>Price</td>
</tr>
{% for x in products %}
<tr>
<td>{{x.name}}</td>
<td>{{x.description}}</td>
<td>₹{{x.price}}</td>
</tr>
{% endfor %}
</table>
<a href="/product/add"><button type="button" class="btn btn-primary">ADD</button></a>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous">
</script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.14.7/dist/umd/popper.min.js"
integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.3.1/dist/js/bootstrap.min.js"
integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM"
crossorigin="anonymous"></script>
</body>

</html>
33 changes: 33 additions & 0 deletions backend/mydjangoproject/firstapp/templates/registration/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.3.1/dist/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<title>Document</title>
</head>

<body>
{% if messages %}
<div class="messages">
{% for message in messages %}
<div class="alert {% if message.tags %}alert-{{ message.tags }}" {% endif %}>
{{ message }}
</div>
{% endfor %}
</div>
{% endif %}
<h2>Login</h2>
<div>
<form method="post">
{% csrf_token %}
{{form.as_p}}
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
<p>Don't have an Account? <a href="/register">Sign up!</a></p>
</body>

</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.3.1/dist/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<title>Document</title>
</head>

<body>
{% if messages %}
<div class="messages">
{% for message in messages %}
<div class="alert {% if message.tags %}alert-{{ message.tags }}" {% endif %}>
{{ message }}
</div>
{% endfor %}
</div>
{% endif %}
<h2>Register</h2>
<div>
<form method="post">
{% csrf_token %}
{{form.as_p}}
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</body>

</html>
15 changes: 15 additions & 0 deletions backend/mydjangoproject/firstapp/templates/timeout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Timeout</title>
</head>

<body>
<h1 style="color: red;">Your Session has expired, Kindly login again.</h1>
<h3><a href="login">Login Again</a></h3>
</body>

</html>
3 changes: 3 additions & 0 deletions backend/mydjangoproject/firstapp/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
16 changes: 16 additions & 0 deletions backend/mydjangoproject/firstapp/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from django.urls import path,include
from . import views

urlpatterns = [
path("product/add/",views.add,name='add'),
path('product/',views.all,name='all'),
path('register',views.register,name='register'),
path('login',views.login__,name='login'),
path('logout',views.logout__,name='logout'),
path('accounts/',include('django.contrib.auth.urls')),
path('',views.home,name='home'),
path('timeout',views.to,name='timeout'),
path('product/<int:id>/',views.viewone,name='viewone'),
path('product/delete/<int:id>/',views.deletep,name='delete'),
path('product/purchase',views.purchase,name='Purchase')
]
Loading