Skip to content

Commit b2b0fa7

Browse files
committed
添加了购物车案例
1 parent 70b6b6e commit b2b0fa7

File tree

23 files changed

+380
-0
lines changed

23 files changed

+380
-0
lines changed

Day31-Day35/shop/cart/__init__.py

Whitespace-only changes.

Day31-Day35/shop/cart/admin.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from django.contrib import admin
2+
3+
from cart.models import Goods
4+
5+
6+
class GoodsAdmin(admin.ModelAdmin):
7+
8+
list_display = ('id', 'name', 'price', 'image')
9+
10+
11+
admin.site.register(Goods, GoodsAdmin)

Day31-Day35/shop/cart/apps.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from django.apps import AppConfig
2+
3+
4+
class CartConfig(AppConfig):
5+
name = 'cart'
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Generated by Django 2.0.5 on 2018-05-25 05:11
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
initial = True
9+
10+
dependencies = [
11+
]
12+
13+
operations = [
14+
migrations.CreateModel(
15+
name='Goods',
16+
fields=[
17+
('id', models.AutoField(db_column='gid', primary_key=True, serialize=False)),
18+
('name', models.CharField(db_column='gname', max_length=50)),
19+
('price', models.DecimalField(db_column='gprice', decimal_places=2, max_digits=10)),
20+
('image', models.CharField(db_column='gimage', max_length=255)),
21+
],
22+
options={
23+
'db_table': 'tb_goods',
24+
'ordering': ('id',),
25+
},
26+
),
27+
]

Day31-Day35/shop/cart/migrations/__init__.py

Whitespace-only changes.

Day31-Day35/shop/cart/models.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from django.db import models
2+
3+
4+
class Goods(models.Model):
5+
6+
id = models.AutoField(primary_key=True, db_column='gid')
7+
name = models.CharField(max_length=50, db_column='gname')
8+
price = models.DecimalField(max_digits=10, decimal_places=2, db_column='gprice')
9+
image = models.CharField(max_length=255, db_column='gimage')
10+
11+
class Meta:
12+
db_table = 'tb_goods'
13+
ordering = ('id',)

Day31-Day35/shop/cart/tests.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.test import TestCase
2+
3+
# Create your tests here.

Day31-Day35/shop/cart/views.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from django.shortcuts import render
2+
3+
from cart.models import Goods
4+
5+
6+
def index(request):
7+
goods_list = list(Goods.objects.all())
8+
return render(request, 'goods.html', {'goods_list': goods_list})
9+
10+
11+
def show_cart(request):
12+
return render(request, 'cart.html')
13+
14+
15+
def add_to_cart(request, no):
16+
pass

Day31-Day35/shop/db.sqlite3

132 KB
Binary file not shown.

Day31-Day35/shop/manage.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env python
2+
import os
3+
import sys
4+
5+
if __name__ == "__main__":
6+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "shop.settings")
7+
try:
8+
from django.core.management import execute_from_command_line
9+
except ImportError as exc:
10+
raise ImportError(
11+
"Couldn't import Django. Are you sure it's installed and "
12+
"available on your PYTHONPATH environment variable? Did you "
13+
"forget to activate a virtual environment?"
14+
) from exc
15+
execute_from_command_line(sys.argv)

0 commit comments

Comments
 (0)