Skip to content

Commit cbfb535

Browse files
committed
Added product_manager models and .gitignore.
1 parent 01281e0 commit cbfb535

4 files changed

Lines changed: 206 additions & 0 deletions

File tree

.gitignore

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
*.egg-info/
24+
.installed.cfg
25+
*.egg
26+
MANIFEST
27+
28+
# PyInstaller
29+
# Usually these files are written by a python script from a template
30+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
31+
*.manifest
32+
*.spec
33+
34+
# Installer logs
35+
pip-log.txt
36+
pip-delete-this-directory.txt
37+
38+
# Unit test / coverage reports
39+
htmlcov/
40+
.tox/
41+
.nox/
42+
.coverage
43+
.coverage.*
44+
.cache
45+
nosetests.xml
46+
coverage.xml
47+
*.cover
48+
.hypothesis/
49+
.pytest_cache/
50+
51+
# Translations
52+
*.mo
53+
*.pot
54+
55+
# Django stuff:
56+
*.log
57+
local_settings.py
58+
db.sqlite3
59+
60+
# Flask stuff:
61+
instance/
62+
.webassets-cache
63+
64+
# Scrapy stuff:
65+
.scrapy
66+
67+
# Sphinx documentation
68+
docs/_build/
69+
70+
# PyBuilder
71+
target/
72+
73+
# Jupyter Notebook
74+
.ipynb_checkpoints
75+
76+
# IPython
77+
profile_default/
78+
ipython_config.py
79+
80+
# pyenv
81+
.python-version
82+
83+
# celery beat schedule file
84+
celerybeat-schedule
85+
86+
# SageMath parsed files
87+
*.sage.py
88+
89+
# Environments
90+
.env
91+
.venv
92+
env/
93+
venv/
94+
ENV/
95+
env.bak/
96+
venv.bak/
97+
98+
# Spyder project settings
99+
.spyderproject
100+
.spyproject
101+
102+
# Rope project settings
103+
.ropeproject
104+
105+
# mkdocs documentation
106+
/site
107+
108+
# mypy
109+
.mypy_cache/
110+
.dmypy.json
111+
dmypy.json

product_manager/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#

product_manager/admin.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from django.contrib import admin
2+
from django import forms
3+
from .models import Product, Category
4+
5+
class ProductAdminForm(forms.ModelForm):
6+
7+
class Meta:
8+
model = Product
9+
fields = '__all__'
10+
11+
12+
class ProductAdmin(admin.ModelAdmin):
13+
form = ProductAdminForm
14+
list_display = ['name', 'slug', 'description', 'price']
15+
readonly_fields = ['name', 'slug', 'description', 'price']
16+
17+
admin.site.register(Product, ProductAdmin)
18+
19+
20+
class CategoryAdminForm(forms.ModelForm):
21+
22+
class Meta:
23+
model = Category
24+
fields = '__all__'
25+
26+
27+
class CategoryAdmin(admin.ModelAdmin):
28+
form = CategoryAdminForm
29+
list_display = ['name', 'slug']
30+
readonly_fields = ['name', 'slug']
31+
32+
admin.site.register(Category, CategoryAdmin)
33+
34+

product_manager/models.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
from django.urls import reverse
2+
from django_extensions.db.fields import AutoSlugField
3+
from django.db.models import *
4+
from django.conf import settings
5+
from django.contrib.contenttypes.fields import GenericForeignKey
6+
from django.contrib.contenttypes.models import ContentType
7+
from django.contrib.auth import get_user_model
8+
from django.contrib.auth import models as auth_models
9+
from django.db import models as models
10+
from django_extensions.db import fields as extension_fields
11+
12+
13+
class Product(models.Model):
14+
15+
# Fields
16+
name = models.CharField(max_length=155)
17+
slug = extension_fields.AutoSlugField(populate_from='name', blank=True)
18+
description = models.TextField(max_length=250)
19+
price = models.DecimalField(max_digits=8, decimal_places=2)
20+
21+
# Relationship Fields
22+
category = models.ForeignKey(
23+
Category, on_delete=models.CASCADE
24+
)
25+
26+
class Meta:
27+
ordering = ('-pk',)
28+
29+
def __unicode__(self):
30+
return u'%s' % self.slug
31+
32+
def get_absolute_url(self):
33+
return reverse('product_manager_product_detail', args=(self.slug,))
34+
35+
36+
def get_update_url(self):
37+
return reverse('product_manager_product_update', args=(self.slug,))
38+
39+
40+
class Category(models.Model):
41+
42+
# Fields
43+
name = models.CharField(max_length=155)
44+
slug = extension_fields.AutoSlugField(populate_from='name', blank=True)
45+
46+
47+
class Meta:
48+
ordering = ('-pk',)
49+
50+
def __unicode__(self):
51+
return u'%s' % self.slug
52+
53+
def get_absolute_url(self):
54+
return reverse('product_manager_category_detail', args=(self.slug,))
55+
56+
57+
def get_update_url(self):
58+
return reverse('product_manager_category_update', args=(self.slug,))
59+
60+

0 commit comments

Comments
 (0)