69 views
Skip to first unread message

Christ Ikonga

unread,
Jan 19, 2021, 8:40:15 AM1/19/21
to django...@googlegroups.com
hi guys i have a question about django form.. how do i use a form i created myself to allow users to register on my site?

Kasper Laudrup

unread,
Jan 19, 2021, 9:04:32 AM1/19/21
to django...@googlegroups.com
On 19/01/2021 01.39, Christ Ikonga wrote:
> hi guys i have a question about django form.. how do i use a form i
> created myself to allow users to register on my site?
>

https://simpleisbetterthancomplex.com/tutorial/2017/02/18/how-to-create-user-sign-up-view.html

Rob Wilkinson

unread,
Jan 19, 2021, 9:06:45 AM1/19/21
to django...@googlegroups.com
Check out my new Django site, wrk in progress..


I can send you my code if it helps

Rob 



On Tue, Jan 19, 2021 at 8:39 AM Christ Ikonga <christi...@gmail.com> wrote:
hi guys i have a question about django form.. how do i use a form i created myself to allow users to register on my site?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CADT9t_rr9uEHAxFjJKOhwNdfUXYBCHCK-wa8JeuLrNJk7ZeZhg%40mail.gmail.com.

Ameto Eklu

unread,
Jan 19, 2021, 4:32:40 PM1/19/21
to django...@googlegroups.com
To use your own form with Django, you have to use widgets in combination with your model attributes.

I hope that answers your question.

On Tue, Jan 19, 2021, 7:39 AM Christ Ikonga <christi...@gmail.com> wrote:
hi guys i have a question about django form.. how do i use a form i created myself to allow users to register on my site?

--

Salima Begum

unread,
Jan 20, 2021, 11:06:12 PM1/20/21
to django...@googlegroups.com
Hi all,

We are building website, Here I have written functionality for classifieds page. 
It is loading to slow because of We are prompting distance calculation in classifieds page. By using distance API matrix based on logged in user zip code and individual Ad zip codes from query set(database).

```
    def classifieds(request):
        global dict_time
        try:
            dict_time = {}
            email = request.session.get('email')

            # Here we are displaying the classified ads "order by date". The ads will be sorted by latest date.
            classifieds = vk_classifieds.objects.filter(class_status='1').order_by('-added_date')
           
            count = vk_classifieds.objects.filter(class_status='1').order_by('-added_date').count()
            for i in classifieds:
                # diff_time is a child method. By passing 'i' as object in diff_time.
                difrnc_date = diff_time(i)
                dict_time[i.id] = difrnc_date

            # Pagination for classifieds page.
            # classified = random.sample(list(classifieds), k=count)
            # print("classified = ", str(classified))
            # By default first page
            page = request.GET.get('page', 1)
            # print("page = ", str(page))
            # Per page setting 40 objects.
            paginator = Paginator(list(classifieds), 40)
            # print("paginator = ", str(paginator))
            classified_p = paginator.page(page)
            # print(classified_p)
        except PageNotAnInteger:
            classified_p = paginator.page(1)
        except EmptyPage:
            classified_p = paginator.page(paginator.num_pages)
        except Exception as e:
            logging.error(e)
            return render(request, "classifieds.html",
                          {"Classifieds": classified_p,
 # distance calculation
                           "distance": classifieds_dist(email),
                           'some_date': dict_time,
                           })
        return render(request, "classifieds.html", {"Classifieds": classified_p,
                                                    "distance": classifieds_dist(email),
                                                    'some_date': dict_time,
                                                    })
```

```

def classifieds_dist(email):
    global frm, km
    dict_distance = {}

    qury = vk_customer.objects.filter(email=email).first()

    # From above qury variable we are getting zip of customer.
    frm = qury.Zip
    # importing json package to calculate the distance
    url = "https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial"
    headers = {
        'Authorization': "Bearer somevalue",
        'User-Agent': "some value",
        'Accept': "*/*",
        'Cache-Control': "no-cache",
        'Postman-Token': "some value",
        'Host': "maps.googleapis.com",
        'Accept-Encoding': "gzip, deflate",
        'Connection': "keep-alive",
        'cache-control': "no-cache"
    }
    classifieds = vk_classifieds.objects.filter(class_status='1').order_by('-added_date')
    for i in classifieds:
        # while a user login through his login email we capture his complete detail into an variable which we given as "qury"
        # and after the details are stored into the variable from there we will filter his starting and destination point as zipcode

        # After login his/her based on email we are filtering in vk_customer table. Then storing in qury variable.

        # This zip is getting from vk_classifieds(model in models.py) table.
        # 'i' attribute is getting from classifieds() function.
        to = i.zip

        origin_list = [to]
        desination_list = [frm]
        # here we used api for calculating the source and destination point
        querystring = {"origins": origin_list, "destinations": desination_list, "departure_time": "now",
                       "key": "AIzaSyDhlCiMAEEfoYhkPcOyP0PLqpHsVMmYEXM"}
        # here we are passing these headers to the api

        # we are capturing the response in variable called response
        response = requests.request("GET", url, headers=headers, params=querystring)
        jsondata = response.text
        obj = json.loads(jsondata)
        list = obj['rows']
        if list:
            a = list[0].get('elements')
            obj2 = a[0].get("distance")
            if obj2 is None:
                km = "None"
            else:
                km = obj2["text"]
            dict_distance[i.id] = km
            l1.append(i.id)
            print("id = ", str(i.id))
            print("km = ", str(km))
    return dict_distance


```

Because of this loading time of classifieds page is to slow. Please help me to solve this issue. 

Thanks
~Salima

Christ Ikonga

unread,
Jan 22, 2021, 10:21:12 PM1/22/21
to django...@googlegroups.com

Florin Ngabire

unread,
Jan 26, 2021, 8:48:12 AM1/26/21
to django...@googlegroups.com
Good after every body so need help someone how has a small Python project in danger framework send me. I am new in Python 

Florin Ngabire

unread,
Jan 26, 2021, 8:53:22 AM1/26/21
to django...@googlegroups.com
Django framework 

Kasper Laudrup

unread,
Jan 26, 2021, 9:01:40 AM1/26/21
to django...@googlegroups.com
Hi Florin,

On 1/26/21 2:43 PM, Florin Ngabire wrote:
> Good after every body so need help someone how has a small Python
> project in danger framework send me. I am new in Python
>

If you follow the Django tutorial, you'll have your own small Python
project in Django. That's a much better way to learn.

But if you're new to Python, I'd recommend learning a bit of Python
first before diving into Django.

Kind regards,

Kasper Laudrup

Chetan Ganji

unread,
Jan 26, 2021, 9:29:41 AM1/26/21
to django...@googlegroups.com

Hi Salima,

Couple of things you can change in the code to make it run faster!
Do these changes and performance will definitely improve.

1.Queryset

Problem:
classifieds = vk_classifieds.objects.filter(class_status='1').order_by('-added_date')
This will fetch all the entries in the table; if there are million records in the table,
all of them will be fetched, which is not required at all!

Processing them will consume resources on the server which is unnecessary calculation!
Avoid it!

Solution:
classifieds = vk_classifieds.objects.filter(class_status='1').order_by('-added_date')[:page_size]

Only fetch what you need! As your page size is 40 actual query will look like below.          
classifieds = vk_classifieds.objects.filter(class_status='1').order_by('-added_date')[:40]

2. Calculation on every request

2.1 classifieds_dist
Distance between two zipcodes is not going to be changed! You dont have to calculate on every request.
Calculate it only once when the new classified is created and store it in a separate table.
This calculation must be done using a celery task.

Every time zipcode of classified is updated or user updates his zipcode, this distance has to be updated.
You have to put restrictions on how many times a user can change his zipcode.
Otherwise you could end up paying hugh money to the api providers!
This updation must be done using a celery task.


2.2 diff_time
I dont know the code and complexity of it.
However as it is going to be required on every request find a way to calculate it once and store in a separate table.

Let me know if they are helpful or not!
Cheers!


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

Christ Ikonga

unread,
Jan 26, 2021, 7:10:09 PM1/26/21
to django...@googlegroups.com
Hi guys.. how I can create a web site with reactjs like frontend and django like Backend ? Help me please

Alam Khazi

unread,
Feb 2, 2021, 1:27:14 AM2/2/21
to django...@googlegroups.com
Thank you chetan I will try it out and let you know

Reply all
Reply to author
Forward
0 new messages