myung's recent timeline updates
myung

myung

V2EX member #248006, joined on 2017-08-11 07:31:56 +08:00
myung's recent replies
Jun 17, 2018
Replied to a topic by myung Django Django channels 服务器部署 应该怎么搞?
@MES
@ericls

我现在是用 daphne 启动在 8001 然后 用 再用 uwsgi 8000 端口 + nginx 启动 网站是可以正常浏览,但是在用 chanels 实现到那个聊天 app 里 无法发送消息, 貌似是需要 nginx 做个转发? 求指点
May 11, 2018
Replied to a topic by myung Django 如何通过一次 post,保存到 2 个表?
@WordTian 单独用都好用 合并到一起就都不好使了
May 11, 2018
Replied to a topic by myung Django 如何通过一次 post,保存到 2 个表?
@WordTian 是的
May 11, 2018
Replied to a topic by myung Django 如何通过一次 post,保存到 2 个表?
@virusdefender 贴到第 2 个附言了。。。贴错 3 次。
May 11, 2018
Replied to a topic by myung Django 如何通过一次 post,保存到 2 个表?
```
def post(self, request):
user = UserProfile.objects.get(username=request.user)
new_goods = Goods(goods_user=user)
goods_from = DaikouForm(request.POST, instance=new_goods)
if goods_from.is_valid():
goods_from.save()
goods = Goods.object.get(id=new_goods.id)
try:
cart = Cart.object.get(cart_id=_cart_id)
except Cart.DoseNotExist:
cart = Cart.object.create(
cart_id = _cart_id(request)
)
cart.save(),
try:
cart_item = CartItem.object.get(goods=goods, cart=cart)
cart_item.quantity += 1
cart_item.save()
except CartItem.DoseNotExist:
cart_item = CartItem.object.create(
goods = goods,
quantity = 1,
cart = cart
)
cart_item.save()
return redirect('cart:cart_detail')
else:
goods_from =DaikouForm()
return redirect('index')
```
May 11, 2018
Replied to a topic by myung Django 如何通过一次 post,保存到 2 个表?
@virusdefender 就是直接把 添加到购物那个函数内容 贴到保存数据库的后面了
May 11, 2018
Replied to a topic by myung Django 如何通过一次 post,保存到 2 个表?
@virusdefender

'''
def post(self, request):
user = UserProfile.objects.get(username=request.user)
new_goods = Goods(goods_user=user)
goods_from = DaikouForm(request.POST, instance=new_goods)
if goods_from.is_valid():
goods_from.save()
goods = Goods.object.get(id=new_goods.id)
try:
cart = Cart.object.get(cart_id=_cart_id)
except Cart.DoseNotExist:
cart = Cart.object.create(
cart_id = _cart_id(request)
)
cart.save(),
try:
cart_item = CartItem.object.get(goods=goods, cart=cart)
cart_item.quantity += 1
cart_item.save()
except CartItem.DoseNotExist:
cart_item = CartItem.object.create(
goods = goods,
quantity = 1,
cart = cart
)
cart_item.save()
return redirect('cart:cart_detail')
else:
goods_from =DaikouForm()
return redirect('index')
'''
May 11, 2018
Replied to a topic by myung Django 如何通过一次 post,保存到 2 个表?
@virusdefender 合并 post 提交 俩函数都不起作用了。。。
May 11, 2018
Replied to a topic by myung Django 如何通过一次 post,保存到 2 个表?
@virusdefender。。我合并了 但是没反应。。
May 10, 2018
Replied to a topic by myung Django 如何通过一次 post,保存到 2 个表?
@Kilerd 能稍微具体些吗。。。我是新手
About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1664 Online   Highest 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 30ms · UTC 16:27 · PVG 00:27 · LAX 09:27 · JFK 12:27
♥ Do have faith in what you're doing.