-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from nyashaChiza/stock
added stock app
- Loading branch information
Showing
16 changed files
with
152 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ share/python-wheels/ | |
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
/staticfiles | ||
MANIFEST | ||
media/ | ||
*.pyc | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from django.contrib import admin | ||
from .models import Gas | ||
|
||
@admin.register(Gas) | ||
class GasAdmin(admin.ModelAdmin): | ||
list_display = ('name', 'quantity', 'price', 'supplier', 'created', 'updated') | ||
list_filter = ('supplier', 'created', 'updated') | ||
search_fields = ('name', 'supplier') | ||
date_hierarchy = 'created' | ||
ordering = ('-created',) | ||
fields = ('name', 'quantity', 'price', 'supplier') | ||
readonly_fields = ('created', 'updated') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class StockConfig(AppConfig): | ||
default_auto_field = 'django.db.models.BigAutoField' | ||
name = 'stock' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Generated by Django 5.0 on 2023-12-28 20:33 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Gas', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=100)), | ||
('quantity', models.PositiveIntegerField()), | ||
('price', models.DecimalField(decimal_places=2, max_digits=8)), | ||
('supplier', models.CharField(blank=True, max_length=100, null=True)), | ||
('created', models.DateTimeField(auto_now_add=True)), | ||
('updated', models.DateTimeField(auto_now=True)), | ||
], | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from django.db import models | ||
|
||
|
||
class Gas(models.Model): | ||
name = models.CharField(max_length=100) | ||
quantity = models.PositiveIntegerField() | ||
price = models.DecimalField(max_digits=8, decimal_places=2) | ||
supplier = models.CharField(max_length=100, null=True, blank=True) | ||
created = models.DateTimeField(auto_now_add=True) | ||
updated = models.DateTimeField(auto_now=True) | ||
|
||
def __str__(self): | ||
return self.name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from django.test import TestCase | ||
from django.urls import reverse | ||
from .models import Gas | ||
from .views import GasListView, GasCreateView | ||
|
||
class GasModelTest(TestCase): | ||
def setUp(self): | ||
self.gas = Gas.objects.create( | ||
name='Gas A', | ||
quantity=10, | ||
price=2.50, | ||
supplier='Supplier A' | ||
) | ||
|
||
def test_gas_model(self): | ||
self.assertEqual(self.gas.name, 'Gas A') | ||
self.assertEqual(self.gas.quantity, 10) | ||
self.assertEqual(self.gas.price, 2.50) | ||
self.assertEqual(self.gas.supplier, 'Supplier A') | ||
self.assertIsNotNone(self.gas.created) | ||
self.assertIsNotNone(self.gas.updated) | ||
|
||
class GasListViewTest(TestCase): | ||
def test_gas_list_view(self): | ||
url = reverse('stock:gas_list') | ||
response = self.client.get(url) | ||
self.assertEqual(response.status_code, 200) | ||
|
||
class GasCreateViewTest(TestCase): | ||
def test_gas_create_view(self): | ||
url = reverse('stock:gas_create') | ||
response = self.client.get(url) | ||
self.assertEqual(response.status_code, 200) | ||
|
||
def test_gas_create_form_submission(self): | ||
url = reverse('stock:gas_create') | ||
data = { | ||
'name': 'Gas B', | ||
'quantity': 5, | ||
'price': 3.00, | ||
'supplier': 'Supplier B' | ||
} | ||
response = self.client.post(url, data) | ||
self.assertEqual(response.status_code, 302) | ||
self.assertEqual(Gas.objects.count(), 1) | ||
gas = Gas.objects.first() | ||
self.assertEqual(gas.name, 'Gas B') | ||
self.assertEqual(gas.quantity, 5) | ||
self.assertEqual(gas.price, 3.00) | ||
self.assertEqual(gas.supplier, 'Supplier B') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from django.urls import path | ||
|
||
from . import views | ||
|
||
app_name = 'stock' | ||
|
||
urlpatterns = [ | ||
path('', views.GasListView.as_view(), name='gas_list'), | ||
path('add/', views.GasCreateView.as_view(), name='gas_create'), | ||
path('<int:pk>/update/', views.GasUpdateView.as_view(), name='gas_update'), | ||
path('<int:pk>/delete/', views.GasDeleteView.as_view(), name='gas_delete'), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from django.shortcuts import render | ||
|
||
# Create your views here. | ||
from django.views.generic import ListView, CreateView, UpdateView, DeleteView | ||
from django.urls import reverse_lazy | ||
from .models import Gas | ||
|
||
class GasListView(ListView): | ||
model = Gas | ||
template_name = 'stock/index.html' | ||
context_object_name = 'gas_items' | ||
|
||
class GasCreateView(CreateView): | ||
model = Gas | ||
template_name = 'stock/create.html' | ||
fields = ['name', 'quantity', 'price', 'supplier'] | ||
success_url = reverse_lazy('stock:gas_list') | ||
|
||
class GasUpdateView(UpdateView): | ||
model = Gas | ||
template_name = 'stock/update.html' | ||
fields = ['name', 'quantity', 'price', 'supplier'] | ||
success_url = reverse_lazy('stock:gas_list') | ||
|
||
class GasDeleteView(DeleteView): | ||
model = Gas | ||
template_name = 'stock/delete.html' | ||
success_url = reverse_lazy('stock:gas_list') |
Empty file.
Empty file.
Empty file.