Commit 0c25a31f authored by jackfrued's avatar jackfrued

修改了Django部分的代码

parent b1bbe89e
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
#container {
width: 960px;
margin: 0 auto;
}
#container iframe {
opacity: 0.5;
}
</style>
</head>
<body>
<div id="container">
<iframe src="http://www.jd.com" width="960" height="800"></iframe>
</div>
<textarea rows="10" cols="50"></textarea>
</body>
</html>
\ No newline at end of file
# Generated by Django 2.0.7 on 2018-08-15 05:45
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('hrs', '0003_auto_20180524_1646'),
]
operations = [
migrations.RemoveField(
model_name='dept',
name='excellent',
),
migrations.AlterField(
model_name='dept',
name='location',
field=models.CharField(db_column='dloc', max_length=10, verbose_name='部门所在地'),
),
migrations.AlterField(
model_name='dept',
name='name',
field=models.CharField(db_column='dname', max_length=20, verbose_name='部门名称'),
),
migrations.AlterField(
model_name='dept',
name='no',
field=models.IntegerField(db_column='deptno', primary_key=True, serialize=False, verbose_name='部门编号'),
),
migrations.AlterField(
model_name='emp',
name='dept',
field=models.ForeignKey(db_column='dno', on_delete=django.db.models.deletion.PROTECT, to='hrs.Dept'),
),
migrations.AlterField(
model_name='emp',
name='job',
field=models.CharField(db_column='job', max_length=10),
),
migrations.AlterField(
model_name='emp',
name='mgr',
field=models.IntegerField(blank=True, null=True),
),
migrations.AlterField(
model_name='emp',
name='name',
field=models.CharField(db_column='ename', max_length=20),
),
migrations.AlterField(
model_name='emp',
name='no',
field=models.IntegerField(db_column='empno', primary_key=True, serialize=False),
),
migrations.AlterModelTable(
name='dept',
table='TbDept',
),
migrations.AlterModelTable(
name='emp',
table='TbEmp',
),
]
...@@ -8,27 +8,28 @@ from django.db import models ...@@ -8,27 +8,28 @@ from django.db import models
class Dept(models.Model): class Dept(models.Model):
no = models.IntegerField(primary_key=True, verbose_name='部门编号') no = models.IntegerField(db_column='deptno', primary_key=True, verbose_name='部门编号')
name = models.CharField(max_length=20, verbose_name='部门名称') name = models.CharField(db_column='dname', max_length=20, verbose_name='部门名称')
location = models.CharField(max_length=10, verbose_name='部门所在地') location = models.CharField(db_column='dloc', max_length=10, verbose_name='部门所在地')
excellent = models.BooleanField(default=0, verbose_name='是否优秀') # excellent = models.BooleanField(default=0, verbose_name='是否优秀')
def __str__(self): def __str__(self):
return self.name return self.name
class Meta: class Meta:
db_table = 'tb_dept' db_table = 'TbDept'
class Emp(models.Model): class Emp(models.Model):
no = models.IntegerField(primary_key=True) no = models.IntegerField(db_column='empno', primary_key=True)
name = models.CharField(max_length=20) name = models.CharField(db_column='ename', max_length=20)
job = models.CharField(max_length=10) job = models.CharField(db_column='job', max_length=10)
mgr = models.ForeignKey('self', null=True, blank=True, on_delete=models.SET_NULL) # mgr = models.ForeignKey('self', null=True, blank=True, on_delete=models.SET_NULL)
# mgr = models.IntegerField(null=True, blank=True) mgr = models.IntegerField(null=True, blank=True)
sal = models.DecimalField(max_digits=7, decimal_places=2) sal = models.DecimalField(max_digits=7, decimal_places=2)
comm = models.DecimalField(max_digits=7, decimal_places=2, null=True, blank=True) comm = models.DecimalField(max_digits=7, decimal_places=2, null=True, blank=True)
dept = models.ForeignKey(Dept, on_delete=models.PROTECT) dept = models.ForeignKey(Dept, db_column='dno', on_delete=models.PROTECT)
class Meta: class Meta:
db_table = 'tb_emp' db_table = 'TbEmp'
...@@ -78,7 +78,7 @@ WSGI_APPLICATION = 'oa.wsgi.application' ...@@ -78,7 +78,7 @@ WSGI_APPLICATION = 'oa.wsgi.application'
DATABASES = { DATABASES = {
'default': { 'default': {
'ENGINE': 'django.db.backends.mysql', 'ENGINE': 'django.db.backends.mysql',
'NAME': 'oa', 'NAME': 'HRS',
'HOST': 'localhost', 'HOST': 'localhost',
'PORT': 3306, 'PORT': 3306,
'USER': 'root', 'USER': 'root',
......
asn1crypto==0.24.0
cffi==1.11.5
cryptography==2.3
Django==2.0.7
idna==2.7
pycparser==2.18
PyMySQL==0.9.2
pytz==2018.5
six==1.11.0
from django.core import serializers
from django.shortcuts import render, redirect from django.shortcuts import render, redirect
from cart.models import Goods from cart.models import Goods
...@@ -25,6 +26,7 @@ class ShoppingCart(object): ...@@ -25,6 +26,7 @@ class ShoppingCart(object):
def __init__(self): def __init__(self):
self.items = {} self.items = {}
self.index = 0
def add_item(self, item): def add_item(self, item):
if item.goods.id in self.items: if item.goods.id in self.items:
...@@ -71,5 +73,5 @@ def add_to_cart(request, id): ...@@ -71,5 +73,5 @@ def add_to_cart(request, id):
def show_cart(request): def show_cart(request):
cart = request.session.get('cart', None) cart = serializers.deserialize(request.session.get('cart'))
return render(request, 'cart.html', {'cart': cart}) return render(request, 'cart.html', {'cart': cart})
...@@ -105,7 +105,7 @@ AUTH_PASSWORD_VALIDATORS = [ ...@@ -105,7 +105,7 @@ AUTH_PASSWORD_VALIDATORS = [
}, },
] ]
SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer' # SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer'
# Internationalization # Internationalization
# https://docs.djangoproject.com/en/2.0/topics/i18n/ # https://docs.djangoproject.com/en/2.0/topics/i18n/
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
<th>商品总价</th> <th>商品总价</th>
<th>操作</th> <th>操作</th>
</tr> </tr>
{% for item in cart.cart_items %} {% for item in cart %}
<tr> <tr>
<td class="name">{{ item.goods.name }}</td> <td class="name">{{ item.goods.name }}</td>
<td class="price">&yen;{{ item.goods.price }}</td> <td class="price">&yen;{{ item.goods.price }}</td>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment