These are chat archives for django/django

14th
Sep 2017
Jennifer Sánchez Dueñas
@Jennifersd
Sep 14 2017 12:56
Hello! I need your help with an error. The error is as follows: "order_created(order.id) TypeError: order_created() missing 1 required positional argument: 'request'".

``` (shift+enter for line break)
from django.shortcuts import render, redirect
from cart.cart import Cart
from .forms import OrderCreateForm
from .models import OrderItem
from .task import order_created
from django.contrib.auth.models import User

def order_create(request):
cart = Cart(request)
if request.method == 'POST':
form = OrderCreateForm(request.POST)
if form.is_valid():
user = request.user
order = form.save()
for item in cart:
OrderItem.objects.create(order=order,
product=item['product'],
price=item['price'],
quantity=item['quantity'])

        # clear the cart
        cart.clear()
        order_created(order.id)
        request.session['order_id'] = order.id
        # redirect to the payment
        return redirect('payment:process')

else:
    form = OrderCreateForm()
return render(request,
              'orders/order/create.html',
              {'cart': cart, 'form': form})

```

Jennifer Sánchez Dueñas
@Jennifersd
Sep 14 2017 13:11
thanks for your help!
Josef Kolář
@thejoeejoee
Sep 14 2017 13:15
@Jennifersd function order_created takes two params
and you're calling it with only one parameter
add request as second parameter
Jennifer Sánchez Dueñas
@Jennifersd
Sep 14 2017 13:19
ok @thejoeejoee that solves my error, now I continue with others :), thank you very much!
Costantin
@Cosbgn
Sep 14 2017 14:08
Hello. In order to access a foreignkey is a nested loop the only way?

My code looks like this:

        all_keywords = SeoKeys.objects.all().exclude(status__in = key_status)
        for key in all_keywords:
            all_metrics = key.seometrics_set.all()
            for metrics in all_metrics:
                update_keyword(key.view_id, key.key_nbr, 2, metrics.seo_url)

Looks fine but I'm wondering if there is a cleaner/more pythonic way

Oğuzhan Yılmaz
@oguzhan-yilmaz
Sep 14 2017 14:10
You can use list comprehensions
But it will probably complicate your code :)
Oğuzhan Yılmaz
@oguzhan-yilmaz
Sep 14 2017 15:13
Hey guys, I am trying to get location data from user but it has to be formatted. So I decided to use django-cities app, but it requires spatial database. So I started to use PostgreSQL. Does anyone has any experience on how to hook django to Postgres spatial database?
Costantin
@Cosbgn
Sep 14 2017 15:26
@oguzhan-yilmaz :D yes it looks quite fine after all! Thanks though
Phong Bui
@loveunCG
Sep 14 2017 16:37
hello
everybdy
talk2shruthivs
@talk2shruthivs
Sep 14 2017 16:40
hello
I have downloaded django-postman package, can someone tell me how to link it to my existing django project ? I am new to django
Phong Bui
@loveunCG
Sep 14 2017 16:47
I gona install paypal api at django project
talk2shruthivs
@talk2shruthivs
Sep 14 2017 16:51
@loveunCG ok
installing API and linking package are they similar ?
Phong Bui
@loveunCG
Sep 14 2017 16:55
thank u reply
please guide me
talk2shruthivs
@talk2shruthivs
Sep 14 2017 17:00
@loveunCG haven't done that before m also new to django
Phong Bui
@loveunCG
Sep 14 2017 17:00
what do u mean
talk2shruthivs
@talk2shruthivs
Sep 14 2017 17:01
@loveunCG I will be of no use in ur case
Oğuzhan Yılmaz
@oguzhan-yilmaz
Sep 14 2017 17:26
You just need to add it to the projects setting file, talk2shruthlvs