this way you'll query all the 'mail_items' table for each country , which
is a time and resource consuming thing to do ..
i think you need to make a separate model that has 2 columns 'country' ,
'mail_items_count' , then you can make a signal when new item saved to
'mail_items'
the signal will update the 'country+mail_items_count' increase the
'mail_items_count' by one ...

inside the 'country+mail_items_count' model you'll make a function to sum
all counts in the 'mail_item_count' column

in your views make a view that query all countries with their ratio :

make a dictionary ,
loop throw each object in the query , take the country name as the key in
the dictionary , take the counter ( integer ) divided by the output of the
sum function to calculate the ratio of each country , append in dictionary
..
send the response with all countries and ratio dictionary ..

On Sat, May 9, 2020 at 3:46 AM hajar <hajarben...@gmail.com> wrote:

> hello! thank you so much for your advice , I want to try to use this view
> function below ,but  for example if you see my models.py I have the class
> mail_items that contains country_origine , I was thinking to do a pie
> chart contains in the labels the countries names and in the data I want
> to make a count to show "which country send items more than the other one"
> I am stack exactly in the data I am still thinking how to this , could you
> advice me please about the queryset
>
> def pie_chart(request):
>         labels = []
>         data = []
>         q = mail_items.objects.all()
>
> for i in q :
>             labels.append()
>             data.append()
>
>         return render(request, 'dash.html', {
>             'labels': labels,
>             'data': data,
>         })
>
>
> Le vendredi 8 mai 2020 23:29:25 UTC+1, _M_A_Y_A_N_K_ a écrit :
>>
>> Hi Hajar,
>>
>> Though you have multiple model, the main thing is to create a queryset.
>> Once you have a queryset (which can be from one model or multiple
>> model).. you should be able to use that queryset for Pie-Charts or any
>> other charts.
>> Also try to use Django-Chart.js, which is much more easier i feel.
>>
>> Hope this helps.
>> Also let know if you face any issue. You can share the queryset for which
>> you need charts.. then probably we can help then.
>>
>> Thanks & Regards,
>> ---------------------
>> Mayank Tripathi
>> Mo. +1 615 962 2128
>> "Do what you can, with what you have, where you are -by Theodore
>> Roosevelt"
>> https://datascience.foundation/datascienceawards
>>
>>
>>
>> On Fri, May 8, 2020 at 5:20 PM hajar Benjat <hajar...@gmail.com> wrote:
>>
>>> Hello everyone how are you doing ?
>>>
>>> I need your suggestions > I have to use a specific models , and I want
>>> to do a  pie_chart view function based on this models , " but I don't know
>>> what to do I saw some view functions examples but they always use one class
>>> but here my classes a bit hard and I am really stack and I need your help "
>>>
>>> this is the models I have to use ,
>>>
>>> from django.db import models
>>>
>>>     # Create your models here.
>>>     class Country(models.Model):
>>>         Country = models.CharField(max_length=100)
>>>
>>>         def __str__(self):
>>>             return '{} '.format(self.Country)
>>>
>>>     class Reason(models.Model):
>>>         Reason_cd = models.IntegerField(blank=True)
>>>         Reason_NM = models.CharField(max_length=100, blank=True)
>>>         def __str__(self):
>>>             return '{}'.format(self.Reason_NM)
>>>
>>>     class Mesure(models.Model):
>>>         Mesure_cd = models.IntegerField(blank=True)
>>>         Mesure_NM = models.CharField(max_length=100,blank=True)
>>>
>>>         def __str__(self):
>>>             return '{}'.format(self.Mesure_NM)
>>>
>>>     class Client(models.Model):
>>>         last_name = models.CharField(max_length=250)
>>>         first_name = models.CharField(max_length=250)
>>>         Adresse = models.CharField(max_length=560)
>>>         city = models.CharField(max_length=100)
>>>         code_postal = models.IntegerField()
>>>         phone number = models.IntegerField(blank=True,null=True)
>>>         mail = models.CharField(max_length=100)
>>>
>>>         def __str__(self):
>>>             return '{}, {}'.format(self.last_name,self.first_name)
>>>
>>>     class Delivery_Agent(models.Model):
>>>         last_name = models.CharField(max_length=250)
>>>         first_name = models.CharField(max_length=250)
>>>
>>>         def __str__(self):
>>>             return '{}, {}  '.format(self.last_name,self.first_name)
>>>
>>>     class Office(models.Model):
>>>         office_cd = models.CharField(max_length=10)
>>>         office_NM = models.CharField(max_length=50)
>>>
>>>         def __str__(self):
>>>             return '{}, {}  '.format(self.office_cd,self.office_NM)
>>>
>>>     class Mail_item_Event(models.Model):
>>>         mail_item_fid = models.CharField(max_length=36)
>>>         Event_cd = models.IntegerField(auto_created=True,unique=True) 
>>> #Event code
>>>         office_Evt_cd = models.ForeignKey(Office, on_delete=models.CASCADE, 
>>> related_name='office_Evt')
>>>         Date_Evt = models.DateTimeField()
>>>         Date_Capture = models.DateTimeField()
>>>         Next_office = models.ForeignKey(Office, on_delete=models.CASCADE, 
>>> related_name='Next_office')
>>>         def __str__(self):
>>>             return '{}'.format(self.Event_cd)
>>>
>>>     class Delivery_info(models.Model):
>>>         mail_item_fid = models.OneToOneField(Mail_item_Event 
>>> ,on_delete=models.CASCADE)
>>>         Event_cd = 
>>> models.OneToOneField(Mail_item_Event,on_delete=models.CASCADE,related_name="delivery_infor_event_cd")
>>>         office_Evt_cd = models.ForeignKey(Office,on_delete=models.CASCADE, 
>>> related_name='office_Evt2')
>>>         Date_Evt = models.DateTimeField()
>>>         Agent_delivery_cd = 
>>> models.ForeignKey(Delivery_Agent,on_delete=models.CASCADE,related_name='agentDelivery')
>>>         Signatory_NM = models.OneToOneField(Delivery_Agent, 
>>> on_delete=models.CASCADE, related_name='signatory')
>>>         Raison_Non_Delivery_cd = 
>>> models.ForeignKey(Reason,on_delete=models.CASCADE, 
>>> related_name='raisonNonDelivery', blank=True)
>>>         def __str__(self):
>>>             return '{}, {} '.format(self.Signatory_NM,self.mail_item_fid)
>>>
>>>     class mail_items(models.Model):
>>>         mail_item_fid = 
>>> models.OneToOneField(Mail_item_Event,on_delete=models.CASCADE)
>>>         Event_cd = 
>>> models.OneToOneField(Mail_item_Event,on_delete=models.CASCADE,related_name="mail_item_event_cd")
>>>         office_Evt_cd = models.ForeignKey(Office,on_delete=models.CASCADE, 
>>> related_name='office_Ev')
>>>         Date_Evt = models.DateTimeField()
>>>         Country_origine = models.ForeignKey(Country, 
>>> on_delete=models.CASCADE ,related_name='paysOrigine')
>>>         Country_destination = 
>>> models.ForeignKey(Country,on_delete=models.CASCADE,related_name='paysDestination')
>>>         Expediteur = 
>>> models.ForeignKey(Client,on_delete=models.CASCADE,related_name='expedi')
>>>         Destinateur = 
>>> models.ForeignKey(Client,on_delete=models.CASCADE,related_name='destin')
>>>
>>>
>>>
>>> --
>>> 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/a88e8341-f6d9-4523-ad87-5a7e17ebb040%40googlegroups.com
>>> <https://groups.google.com/d/msgid/django-users/a88e8341-f6d9-4523-ad87-5a7e17ebb040%40googlegroups.com?utm_medium=email&utm_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/858efda6-0183-4b5f-8e54-7a18cd25cc71%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/858efda6-0183-4b5f-8e54-7a18cd25cc71%40googlegroups.com?utm_medium=email&utm_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/CAHV4E-dbmSXYB7qm1u8BDp369L53bQ8jLXN9zrL4o6hkfKZVXw%40mail.gmail.com.

Reply via email to