Skip to content

Commit

Permalink
Merge pull request #2 from ebauschatz/app_creation
Browse files Browse the repository at this point in the history
Adding products app, model, and serializer
  • Loading branch information
ebauschatz committed Sep 23, 2022
2 parents bec6eb9 + 83808b4 commit fe702d1
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 0 deletions.
Empty file added products/__init__.py
Empty file.
4 changes: 4 additions & 0 deletions products/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from django.contrib import admin
from .models import Product

admin.site.register(Product)
6 changes: 6 additions & 0 deletions products/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class ProductsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'products'
24 changes: 24 additions & 0 deletions products/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 4.1.1 on 2022-09-23 15:02

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')),
('title', models.CharField(max_length=255)),
('description', models.CharField(max_length=255)),
('price', models.DecimalField(decimal_places=2, max_digits=9)),
('inventory_quantity', models.IntegerField()),
],
),
]
Empty file added products/migrations/__init__.py
Empty file.
7 changes: 7 additions & 0 deletions products/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.db import models

class Product(models.Model):
title = models.CharField(max_length=255)
description = models.CharField(max_length=255)
price = models.DecimalField(max_digits=9, decimal_places=2)
inventory_quantity = models.IntegerField()
7 changes: 7 additions & 0 deletions products/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from rest_framework import serializers
from .models import Product

class ProductSerializer(serializers.ModelSerializer):
class Meta:
model = Product
fields = ['title', 'description', 'price', 'inventory_quantity']
3 changes: 3 additions & 0 deletions products/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.
3 changes: 3 additions & 0 deletions products/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.shortcuts import render

# Create your views here.
1 change: 1 addition & 0 deletions products_project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'products',
]

MIDDLEWARE = [
Expand Down

0 comments on commit fe702d1

Please sign in to comment.