How to display a line graph in Django?

2020-06-30 Thread ratnadeep ray
Hi all, 

I have wrote a python program to display the line graph as follows: 

import matplotlib.pyplot as plt 

x = [1,2,3] 
y = [2,4,1] 
  

plt.plot(x, y) 
  

plt.xlabel('x - axis') 
plt.ylabel('y - axis') 
  

plt.title('My first graph!') 
  
plt.show()


Now I need to display the same via Django. So I think I need to write the 
above code in the view and then redirect the same to the html template 
file. Am I right? 

In that case, how to send the request objects related to the line chart to 
the template? 

Normally, we send in the following format: 

def view1(request)


 return render(request, 'display_report.html', { 'var1': "abc", ...
 ... })

So if we are trying to display the line graph generated by the above code, 
how to do so ? 

Please share your inputs. 

Thanks. 


-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/827e0d0c-6bbb-4511-af73-9fa379df699do%40googlegroups.com.


How to pass values of drop down from html template to views in Django?

2020-06-26 Thread ratnadeep ray


I need to send the value of the selected option in a drop down to the views.

My html code is as follows:

> 
> Select version to compare with
> {%for ver in version_list%}
> **{{ver}} option>**
> {% endfor %}
> 


The above is giving me the following error:

> Page not found (404)
> Request Method: GET
> Request URL: http://127.0.0.1:8000/index/11.5.1.18900-96
> http://127.0.0.1:8000/index/11.5.1.18900-97
> Using the URLconf defined in Piechart_Excel.urls, Django tried these URL 
> patterns, in this order:
> admin/
> index/
> process_data/ [name='process_data']
> The current path, index/11.5.1.18900-96, didn't match any of these.


However if I am sending the value as follows i.e. without any drop down:

> {{ver}}


everything is working as expected.


My urls.py file content is as follows:


from django.urls import path
> from fusioncharts import views urlpatterns
> urlpatterns = [
> path('index/', views.index, name='index'),
> path('process_data/', views.process_data, name='process_data'),
> ] 

Can anyone say why is it not working in the case of drop down but working 
otherwise? If we have to send any value from the html template using drop 
down, then how to do so?

Thanks.

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/da72e367-bc90-46cd-8b54-3502d1a126b9o%40googlegroups.com.


Re: Reverse for 'process_data' not found. 'process_data' is not a valid view function or pattern name.

2020-06-26 Thread ratnadeep ray
Hi Ogunasya, 

I tried that but still that's not working. After some research and 
analysis, I realized the issue is not with the urls but with the html file. 
When I am trying to direct to the url in the href via drop-down only, the 
error is coming. But if we I am trying to access the same url via table, it 
is working fine. 

So to summarize: 
*Working: *
{{ver}}


*Non-working: *
{{ver}}

Can you please suggest what is going wrong ? How can we reach the method 
'process_data' using dropdown ? 

On Thursday, 25 June 2020 12:08:12 UTC+5:30, Ogunsanya Opeyemi wrote:
>
> Also include in your URL before your urlpatterns 
>
> app_name=yourappname
>
>
> And in your template URL  write
> {% url 'yourappname:process_data' ver %}
>
>
>
> And if you still have issues send the update you made and let me check.
>
> On Thursday, June 25, 2020, ratnadeep ray  > wrote:
>
>> Hi Ogunsanya, 
>>
>> I have added that line of code but still getting the same error. 
>>
>> So what can be done next ? 
>>
>> On Thursday, 25 June 2020 00:25:17 UTC+5:30, Ogunsanya Opeyemi wrote:
>>>
>>>
>>> Yes
>>> On Wednesday, June 24, 2020, ratnadeep ray  wrote:
>>>
>>>> So I need to add this also:
>>>>
>>>>
>>>>
>>>> urlpatterns = [
>>>> ...
>>>> ...
>>>> path('process_data/', views.process_data, name='process_data'),
>>>>
>>>> -- 
>>>> 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...@googlegroups.com.
>>>> To view this discussion on the web visit 
>>>> https://groups.google.com/d/msgid/django-users/5c62826f-a652-43c3-a89e-29cf1855a9f8o%40googlegroups.com
>>>> .
>>>>
>>>
>>>
>>> -- 
>>> OGUNSANYA OPEYEMI
>>>
>>> -- 
>> 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...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/bb999e9e-5fd9-45ec-9a59-86e3ed9b6454o%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/bb999e9e-5fd9-45ec-9a59-86e3ed9b6454o%40googlegroups.com?utm_medium=email_source=footer>
>> .
>>
>
>
> -- 
> OGUNSANYA OPEYEMI
>
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/db746050-5807-4b00-847f-3c3077faccb2o%40googlegroups.com.


Re: Reverse for 'process_data' not found. 'process_data' is not a valid view function or pattern name.

2020-06-25 Thread ratnadeep ray
Hi Ogunsanya,

Now I added the same as per your suggestion. Following is my urls.py 
contnent

from django.urls import path
from fusioncharts import views
app_name = 'fusioncharts'


urlpatterns = [
path('push-data/', views.push_data, name='push-data'),
path('home/', views.home, name='home'),
path('display_data/', views.display_data, name=
'display_data'),
path('index/', views.index, name=''),
*path**('process_data/', views.process_data, 
name='process_data'),*
]

And my template content (process_data.py)is as follows: 




Home


  
  Index page
  
  Select the version to compare with
  
 Select version to compare with
 {%for ver in version_list%}
 
{{ver}}
 {% endfor %}
  
  
  The current version{{version}}
  
  
  




But now I am getting the following error: 

Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/index/11.5.1.18900-96
http://127.0.0.1:8000/index/11.5.1.18900-97


Using the URLconf defined in Piechart_Excel.urls, Django tried these URL 
patterns, in this order:
admin/
push-data/ [name='push-data']
home/ [name='home']
display_data/ [name='display_data']
index/
process_data/ [name='process_data']

The current path, index/11.5.1.18900-96, didn't match any of these.


Can you suggest now what's going wrong ? 



On Thursday, 25 June 2020 12:08:12 UTC+5:30, Ogunsanya Opeyemi wrote:
>
> Also include in your URL before your urlpatterns 
>
> app_name=yourappname
>
>
> And in your template URL  write
> {% url 'yourappname:process_data' ver %}
>
>
>
> And if you still have issues send the update you made and let me check.
>
> On Thursday, June 25, 2020, ratnadeep ray  > wrote:
>
>> Hi Ogunsanya, 
>>
>> I have added that line of code but still getting the same error. 
>>
>> So what can be done next ? 
>>
>> On Thursday, 25 June 2020 00:25:17 UTC+5:30, Ogunsanya Opeyemi wrote:
>>>
>>>
>>> Yes
>>> On Wednesday, June 24, 2020, ratnadeep ray  wrote:
>>>
>>>> So I need to add this also:
>>>>
>>>>
>>>>
>>>> urlpatterns = [
>>>> ...
>>>> ...
>>>> path('process_data/', views.process_data, name='process_data'),
>>>>
>>>> -- 
>>>> 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...@googlegroups.com.
>>>> To view this discussion on the web visit 
>>>> https://groups.google.com/d/msgid/django-users/5c62826f-a652-43c3-a89e-29cf1855a9f8o%40googlegroups.com
>>>> .
>>>>
>>>
>>>
>>> -- 
>>> OGUNSANYA OPEYEMI
>>>
>>> -- 
>> 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...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/bb999e9e-5fd9-45ec-9a59-86e3ed9b6454o%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/bb999e9e-5fd9-45ec-9a59-86e3ed9b6454o%40googlegroups.com?utm_medium=email_source=footer>
>> .
>>
>
>
> -- 
> OGUNSANYA OPEYEMI
>
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/14aca6b8-8bc9-455a-b3c6-de0c8740a9a7o%40googlegroups.com.


Re: Reverse for 'process_data' not found. 'process_data' is not a valid view function or pattern name.

2020-06-24 Thread ratnadeep ray
Hi Ogunsanya, 

I have added that line of code but still getting the same error. 

So what can be done next ? 

On Thursday, 25 June 2020 00:25:17 UTC+5:30, Ogunsanya Opeyemi wrote:
>
>
> Yes
> On Wednesday, June 24, 2020, ratnadeep ray  > wrote:
>
>> So I need to add this also:
>>
>>
>>
>> urlpatterns = [
>> ...
>> ...
>> path('process_data/', views.process_data, name='process_data'),
>>
>> -- 
>> 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...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/5c62826f-a652-43c3-a89e-29cf1855a9f8o%40googlegroups.com
>> .
>>
>
>
> -- 
> OGUNSANYA OPEYEMI
>
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/bb999e9e-5fd9-45ec-9a59-86e3ed9b6454o%40googlegroups.com.


Re: Reverse for 'process_data' not found. 'process_data' is not a valid view function or pattern name.

2020-06-24 Thread ratnadeep ray
So I need to add this also:



urlpatterns = [
...
...
path('process_data/', views.process_data, name='process_data'),

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5c62826f-a652-43c3-a89e-29cf1855a9f8o%40googlegroups.com.


Reverse for 'process_data' not found. 'process_data' is not a valid view function or pattern name.

2020-06-24 Thread ratnadeep ray
Hi all,

Any comment on this?

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/852e2f1b-fcfc-43a9-b098-9170579a8f56o%40googlegroups.com.


Reverse for 'process_data' not found. 'process_data' is not a valid view function or pattern name.

2020-06-24 Thread ratnadeep ray
Hi all, 

I am trying to direct the option selected from the dropdown in the 
index.html along with the value to the process_data method in the views.py. 
But now I am getting the following error when I am trying to load my index 
page: 

NoReverseMatch at /index/

Reverse for 'process_data' not found. 'process_data' is not a valid view 
function or pattern name.




My index.html file is as follows: 




Home


  
  Index page
  
  Select the version to compare with
  
 Select version to compare with
 {%for ver in version_list%}
 {{ver}}
 {% endfor %}
  
  
  The current version{{version}}
  
  
  



My view file content is like this: 

def index(request):
#query_results = QRC_DB.objects.all()
global percentage_variation
percentage_variation = 0
global version
version = None 
context = RequestContext(request)
response_context = get_result(request)
#print("The response_context values  = \n %s" 
%response_context.get("get_result"))
cursor  = connection.cursor()
cursor.execute("select version from fusioncharts_qrc_db group by 
version")
rows = cursor.fetchall()
#print("The fetched rows =\n")
#print(rows)
version_list = []
#print(version_list)
for ver in rows:
version = str(ver).split("'")[1]
version_list.append(version)

print("The final version list = %s" %version_list)
return render(request, 'index.html', {
'version': version, 
'version_list': version_list,
})


def process_data(request,ver):

print("==The version selected = %s===" %ver)

return render(request, 'display_data.html', {
'version': version, 
  
})


The url file contents are as follows: 

from django.urls import path
from fusioncharts import views


urlpatterns = [
path('push-data/', views.push_data, name='push-data'),
path('home/', views.home, name='home'),
path('display_data/', views.display_data, name=
'display_data'),
path('index/', views.index, name='index'),
]

from django.contrib import admin
from django.urls import path,include


urlpatterns = [
path('admin/', admin.site.urls),
path('', include('fusioncharts.urls'))
]

Can anyone please help me why the above error is coming and how to fix that 
? 

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6b391dfb-f423-4c8f-b713-73c4879ffe34o%40googlegroups.com.


Can we use python related api's on the Django templates ?

2020-05-27 Thread ratnadeep ray
Hi all, 

Currently I am trying to print the type of a variable from the Django 
template html file as follows: 

The type of feature list report for version 
> {%type(version)%} is


For the above, I am getting the following error: 

Invalid block tag on line 9: 'type(version)'. Did you forget to register or 
load this tag?


So what's going wrong here? How can we use the python related api's (like 
type) from the html template files? I think inside the {%  %} we can 
use python related evaluations. Am I right? 

Please throw some lights on this .

Thanks. 

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2863977e-c712-4746-bbb0-b175bc976a0d%40googlegroups.com.


Re: How to retrieve the values from the context_process.py file to template?

2020-05-26 Thread ratnadeep ray
So what should be the correction in my case?

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5195d557-7c89-4814-b7ca-46d64234a15d%40googlegroups.com.


Re: How to retrieve the values from the context_process.py file to template?

2020-05-26 Thread ratnadeep ray
So for this we have to import the model of context_process ?

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/11fb0baa-0782-4ef4-8069-215fb679b334%40googlegroups.com.


How to retrieve the values from the context_process.py file to template?

2020-05-26 Thread ratnadeep ray
Hi all, 

I am trying to display the value from the context_process.py file to the 
template. 

The content of my context_process.py is as follows: 

from fusioncharts.models import QRC_DB
from django.db import connection

def get_result(request):
> cursor  = connection.cursor()
> pattern = "%%"+TotalTime+"%%"
> cursor.execute("select * from fusioncharts_qrc_db")
> rows = cursor.fetchall()
> return {'get_result': rows}


Then in the html template file, I am trying to display the variable 
get_result as follows: 

{% block content %}
>Result = 
>   
>   {{get_result}}
>
> {% endblock %}


My template details in the settings.py is as follows: 

 

> TEMPLATES = [
> {
> ...
> 'OPTIONS': {
> 'context_processors': [
> .
> 'fusioncharts.context_processors.get_result',
> ],
> },
> },
> ]


My views.py file is as follows: 

def home(request):
> context = RequestContext(request)
> response_context = {}
> return render(request, 'display_data.html',response_context)



But when I am running that, it is not displaying anything in the web page. 

Is there anything missing in my code? What is going wrong here? 





-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/aa0a33a7-3cb8-4cc5-9ccb-c95cddd83c67%40googlegroups.com.


Getting the except django.core.exceptions.ImproperlyConfigured while querying DB

2020-05-20 Thread ratnadeep ray
I am trying to fetch a few rows from the DB using the following code in my 
views.py:

from django.http import HttpResponsefrom django.shortcuts import renderfrom 
fusioncharts.models import QRC_DB
def display_data(request,component):
query_results = QRC_DB.objects.get(component_name__contains=component)
return HttpResponse("You're looking at the component %s." % component)

For the above, I am getting the following exception:

django.core.exceptions.ImproperlyConfigured: The included URLconf 
'Piechart_Excel.urls' does not appear to have any patterns in it. If you see 
valid patterns in the file then the issue is probably caused by a circular 
import.

However whenever I am *removing/commenting out* the below line, the above 
exception disappears:

query_results = QRC_DB.objects.get(component_name__contains=component)


Can anyone say what can be going wrong here? 

urls.py file under app is as follows: 

from django.urls import path from fusioncharts import views urlpatterns 
urlpatterns 
> = [
> path('push-data/', views.push_data, name='push-data'),
> path('home/', views.home, name='home'),
> path('display_data/', views.display_data, name=
> 'display_data'),
> ]

The url under the main project is as follows: 

from django.contrib import adminfrom django.urls import path,include
>
> urlpatterns urlpatterns = [
> path('admin/', admin.site.urls),
> path('', include('fusioncharts.urls'))
> ]

So please advise what's going wrong. 

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0acc7888-9e25-43fd-8a50-64fe43086190%40googlegroups.com.


Reverse for 'display_data' not found. 'display_data' is not a valid view function or pattern name

2020-05-19 Thread ratnadeep ray
Hi all, 

I am getting the below error when I am trying to load the home page:
Reverse for 'display_data' not found. 'display_data' is not a valid view 
function or pattern name

My views.py file is as follows: 

 

> def home(request):
> #query_results = QRC_DB.objects.all()
> return render(request, 'display_data.html')
>
> def display_data(request,component):
> #query_results = QRC_DB.objects.all()
> return HttpResponse("You're looking at the component %s." % component)


My urls.py file under the app is as follows: 

from django.urls import path
from fusioncharts import views

urlpatterns = [
> path('home/', views.home, name=''),
> ]


The urls.py file under the project is as follows: 

from django.contrib import admin
> from django.urls import path,include
> urlpatterns = [
> path('admin/', admin.site.urls),
> path('', include('fusioncharts.urls'))
> ]



And my html file (display_data) code is as follows : 

>
> {% block content %}
>   Display the test results
>   
> 
> SQL
>   
> {% endblock %}




Can anyone please help me to find out the mistake ? 

Thanks. 

 

 


-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/31ce205c-b54c-484f-8928-350eb91178a6%40googlegroups.com.


How to pass a variable to views from a template using href ?

2020-05-19 Thread ratnadeep ray
Hi all, 

My requirement is to pass a variable to the view from the template using 
href. 

For example, I have written the following line of code: 

SQL data


So using the above line, can we send the value "SQL" clicking on the link 
of "SQL data" to the method "execute" written in the views? If not, then 
what way can I do so? 

Thanks. 





-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7e892826-f4c1-426d-bf9b-1a1b0b2b17be%40googlegroups.com.


Re: Django foreign-key cannot assign must be a instance

2020-05-19 Thread ratnadeep ray
Can you please say in which line we should make that change because in so 
many places I am using comp. So in all the places should I change that ?

On Tuesday, 19 May 2020 12:36:19 UTC+5:30, Aldian Fazrihady wrote:
>
> Use comp_id= instead of comp=
>
> Regards, 
>
> Aldian Fazrihady
> http://aldianfazrihady.com
>
> Pada tanggal Sel, 19 Mei 2020 13.49, ratnadeep ray  > menulis:
>
>> Hi all, 
>>
>> I am trying to add a row in the DB using the following views.py: 
>>
>> # Create your views here.
>>> from django.shortcuts import render
>>> from fusioncharts.models import Component,Report
>>> import xlrd
>>> def pie_chart(request):
>>> labels = []
>>> data = []
>>> loc = ("C:\Django_apps\QRC_Report.xlsx")
>>> workbook = xlrd.open_workbook(loc) 
>>> worksheet = workbook.sheet_by_name('Sheet1')
>>> num_rows = worksheet.nrows - 1
>>> num_cols = worksheet.ncols - 1
>>> curr_row = -1
>>> component = []
>>> comp = None 
>>> while curr_row < num_rows:
>>>   curr_row += 1
>>>   row = worksheet.row(curr_row)
>>>   curr_col = -1
>>>   if "Header" in worksheet.cell_value(curr_row, 0):
>>> compon = worksheet.cell_value(curr_row, 0).strip("*")
>>> print("The component is %s" %compon)
>>> component.append(compon)
>>> print("===The results of the component %s is as 
>>> follows" %compon)
>>> Component.objects.create(comp=compon)
>>> continue
>>>   while curr_col < num_cols:
>>> curr_col += 1
>>> cell_value = worksheet.cell_value(curr_row, curr_col)
>>> #print("Cell value = %s" %cell_value)
>>> test_name = worksheet.cell_value(curr_row,0)
>>> print("Test name = %s" %test_name)
>>> test_value = worksheet.cell_value(curr_row,1)
>>> print("Test result = %s" %test_value)
>>> print("The component is = %s" %comp)
>>> 
>>> *Report.objects.create(param=test_name,comp=compon,value=test_value)*
>>> return render(request, 'pie_chart.html', {
>>> 'labels': labels,
>>> 'data': data,
>>> })
>>
>>
>> However the above highlighted line is throwing the following error: 
>>
>>> Cannot assign "'Header SQL Detailed'": "Report.comp" must be a 
>>> "Component" instance.
>>
>>
>> My model is as follows: 
>>
>> from django.db import models
>>> from django.urls import reverse
>>> from decimal import Decimal
>>> # Create your models here.
>>> class Component(models.Model):
>>> comp = models.CharField(max_length=30)
>>> class Report(models.Model):
>>> comp = models.ForeignKey(Component,on_delete=models.CASCADE)
>>> param = models.CharField(max_length=30)
>>> value = 
>>> models.DecimalField(max_digits=25,decimal_places=18,default=Decimal('0.'))
>>
>>
>>
>> Can anyone please point out what is going wrong here? What should be the 
>> correction? 
>>
>> Thanks. 
>>
>> -- 
>> 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...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/afb5a06a-0d7d-4038-a0fc-3c2aadbbe4fc%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/afb5a06a-0d7d-4038-a0fc-3c2aadbbe4fc%40googlegroups.com?utm_medium=email_source=footer>
>> .
>>
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1425af8b-7dae-4cdb-ba8a-82d0a9fa0a74%40googlegroups.com.


Django foreign-key cannot assign must be a instance

2020-05-19 Thread ratnadeep ray
Hi all, 

I am trying to add a row in the DB using the following views.py: 

# Create your views here.
> from django.shortcuts import render
> from fusioncharts.models import Component,Report
> import xlrd
> def pie_chart(request):
> labels = []
> data = []
> loc = ("C:\Django_apps\QRC_Report.xlsx")
> workbook = xlrd.open_workbook(loc) 
> worksheet = workbook.sheet_by_name('Sheet1')
> num_rows = worksheet.nrows - 1
> num_cols = worksheet.ncols - 1
> curr_row = -1
> component = []
> comp = None 
> while curr_row < num_rows:
>   curr_row += 1
>   row = worksheet.row(curr_row)
>   curr_col = -1
>   if "Header" in worksheet.cell_value(curr_row, 0):
> compon = worksheet.cell_value(curr_row, 0).strip("*")
> print("The component is %s" %compon)
> component.append(compon)
> print("===The results of the component %s is as 
> follows" %compon)
> Component.objects.create(comp=compon)
> continue
>   while curr_col < num_cols:
> curr_col += 1
> cell_value = worksheet.cell_value(curr_row, curr_col)
> #print("Cell value = %s" %cell_value)
> test_name = worksheet.cell_value(curr_row,0)
> print("Test name = %s" %test_name)
> test_value = worksheet.cell_value(curr_row,1)
> print("Test result = %s" %test_value)
> print("The component is = %s" %comp)
> 
> *Report.objects.create(param=test_name,comp=compon,value=test_value)*
> return render(request, 'pie_chart.html', {
> 'labels': labels,
> 'data': data,
> })


However the above highlighted line is throwing the following error: 

> Cannot assign "'Header SQL Detailed'": "Report.comp" must be a "Component" 
> instance.


My model is as follows: 

from django.db import models
> from django.urls import reverse
> from decimal import Decimal
> # Create your models here.
> class Component(models.Model):
> comp = models.CharField(max_length=30)
> class Report(models.Model):
> comp = models.ForeignKey(Component,on_delete=models.CASCADE)
> param = models.CharField(max_length=30)
> value = 
> models.DecimalField(max_digits=25,decimal_places=18,default=Decimal('0.'))



Can anyone please point out what is going wrong here? What should be the 
correction? 

Thanks. 

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/afb5a06a-0d7d-4038-a0fc-3c2aadbbe4fc%40googlegroups.com.


How to display multiple pie charts based on multiple lists?

2020-05-12 Thread ratnadeep ray
Hi all, 

I have a requirement where I need to display multiple pie charts based on 
multiple lists. 

Currently, I am able to display one pie chart involving 2 lists. Below is 
the views.py code for the same: 

# Create your views here.
from django.shortcuts import render

def pie_chart(request):
labels = ["A", "B", "C"]
data = ["10", "15", "2"]

   return render(request, 'pie_chart.html', {
'labels': labels,
'data': data,
})

Now what if we have another pair of lists as follows: 
labels1 = ["X", "Y", "Z"]
data1 = ["10", "15", "2"]

So can anyone say what changes should I made in the above code  to display 
2 pie charts displaying labels/data and labels1/data1 ? 

Thanks in advance. 

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8308ffd5-68f5-47ff-883d-05b6a22795c8%40googlegroups.com.


Re: How to push data fetched from excel to DB using Django?

2020-05-08 Thread ratnadeep ray
Thanks Derek for this. 

On Friday, 8 May 2020 19:20:31 UTC+5:30, Derek wrote:
>
> If you can, use an existing app:
>
> https://github.com/wq/django-data-wizard
>
>
> On Friday, 8 May 2020 14:57:43 UTC+2, Kasper Laudrup wrote:
>>
>> Hi Ratnadeep, 
>>
>> On 08/05/2020 14.03, ratnadeep ray wrote: 
>> > Hi all, 
>> > 
>> > Can anyone let me know how to push the fetched data from an excel to 
>> any 
>> > DB using Django? 
>> > 
>>
>> It's not very clear what you mean by "the fetched data". Have you 
>> fetched some data already? In which format? 
>>
>> If you need to extract data from an excel sheet, this was the first 
>> guide I could find: 
>>
>> https://www.geeksforgeeks.org/reading-excel-file-using-python/ 
>>
>> Also, "any DB" is extremely vague. Do you have a database already? Or do 
>> you just want to go for whatever database is the best suited for 
>> whatever you are trying to achieve? 
>>
>> And what exactly do you want to use Django for? Django is a web 
>> framework and nothing in your question mentions anything about that... 
>>
>> Kind regards, 
>>
>> Kasper Laudrup 
>>
>>
>>
>>
>>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4cca72a6-1b5d-4fa8-8c60-c3593cdaca90%40googlegroups.com.


Re: How to push data fetched from excel to DB using Django?

2020-05-08 Thread ratnadeep ray
Hi Kasper, 

I want to read the data from excel and the retrieved data should be pushed 
to a DB, in my case it's MySQL. 

I believe the steps mentioned in the link 
https://www.geeksforgeeks.org/reading-excel-file-using-python/ , should be 
written in the views.py file. Am I right? 

Please clarify these because I am pretty new to Django. 

Thanks. 

On Friday, 8 May 2020 18:27:43 UTC+5:30, Kasper Laudrup wrote:
>
> Hi Ratnadeep, 
>
> On 08/05/2020 14.03, ratnadeep ray wrote: 
> > Hi all, 
> > 
> > Can anyone let me know how to push the fetched data from an excel to any 
> > DB using Django? 
> > 
>
> It's not very clear what you mean by "the fetched data". Have you 
> fetched some data already? In which format? 
>
> If you need to extract data from an excel sheet, this was the first 
> guide I could find: 
>
> https://www.geeksforgeeks.org/reading-excel-file-using-python/ 
>
> Also, "any DB" is extremely vague. Do you have a database already? Or do 
> you just want to go for whatever database is the best suited for 
> whatever you are trying to achieve? 
>
> And what exactly do you want to use Django for? Django is a web 
> framework and nothing in your question mentions anything about that... 
>
> Kind regards, 
>
> Kasper Laudrup 
>
>
>
>
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/92c1e4f6-35a8-47f2-ab1a-79809fef8b05%40googlegroups.com.


How to push data fetched from excel to DB using Django?

2020-05-08 Thread ratnadeep ray
Hi all, 

Can anyone let me know how to push the fetched data from an excel to any DB 
using Django? 

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1e970207-0c86-4925-b4c8-dbce7c7c069d%40googlegroups.com.


django.core.exceptions.ImproperlyConfigured: error is coming

2020-05-08 Thread ratnadeep ray
I am new to Django and hence don't have much idea about it. I am trying to 
create an app having the following contents in my view.py file:

from django.shortcuts import render
> from fusioncharts.models import City
> def pie_chart(request):
> labels = []
> data = []
> queryset = City.objects.order_by('-population')[:3]
> for city in queryset:
> labels.append(city.name)
> data.append(city.population)
> return render(request, 'pie_chart.html', {
> 'labels': labels,
> 'data': data,
> })


The content of my urls.py file inside the app is as follows:

from django.urls import path
> from fusioncharts import views
> urlpatterns = [
> path('pie-chart/', views.pie_chart, name='pie-chart'),
> ]


and the content of my urls.py file inside the main project folder is as 
follows:

from django.contrib import admin
> from django.urls import path
> urlpatterns = [
> path('admin/', admin.site.urls),
> path('', include('fusioncharts.urls'))
> ]


In the settings.py file, I have added the following:

ROOT_URLCONF = 'Piechart.urls'


and under the TEMPLATES, added the following:

'DIRS': ['Piechart/fusioncharts/templates'], 


Now while running my app, I am getting the following error:

*django.core.exceptions.ImproperlyConfigured: The included URLconf 
> 'Piechart.urls' does not appear to have any patterns in it. If you see 
> valid patterns in the file then the issue is probably caused by a circular 
> import.*


Can anyone please say what's going wrong?

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8afd3990-d71b-4783-a478-0b18bf05389f%40googlegroups.com.


How to display pie chart using Django

2020-05-07 Thread ratnadeep ray
Hi all, 

I just started to work on Django and hence have limited knowledge about it. 

Now I need to design an app to display a pie chart based on some sample 
data. Can anybody please help me to do so? Is there any sample app existing 
which fulfills this requirement ? 

Thanks. 

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/84036bfa-ddfb-451b-98ff-27fffcfb151c%40googlegroups.com.