CHOICES

2021-06-13 Thread www.forum-gh.com
Hello friends
please i have: conversion_fqctor = models.charfield(choices=FACTOR)

i want to sum the conversion_factor inside my view.py how do i convert it
to a decimal and use the Sum()

-- 
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/CALYpPT8_5sMsyjzvpdGZ3gBQbqiwQW7EHgZ61i4LdLQ1z38LYg%40mail.gmail.com.


Re: CHOICES

2021-06-13 Thread Sebastian Jung
Hello,

i think this is the right answer:

from django.db.models import Sum

ModelName.objects.filter(field_name__isnull=True).aggregate(Sum('field_name'))#
returns {'field_name__sum': 1000} for example


Am So., 13. Juni 2021 um 12:04 Uhr schrieb www.forum-gh.com <
ladamo...@gmail.com>:

> Hello friends
> please i have: conversion_fqctor = models.charfield(choices=FACTOR)
>
> i want to sum the conversion_factor inside my view.py how do i convert it
> to a decimal and use the Sum()
>
> --
> 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/CALYpPT8_5sMsyjzvpdGZ3gBQbqiwQW7EHgZ61i4LdLQ1z38LYg%40mail.gmail.com
> 
> .
>

-- 
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/CAKGT9mzh5hoTgESsxFiUtkT_S-cPvTSjNGp-zUAfSwSptAaZJw%40mail.gmail.com.


Re: Make permissions according branch id

2021-06-13 Thread Nikeet NA
What you are trying to do is called object-level permission in Django, 
normally people use is model-level permission, you can use this module Django 
guardian .

On Sunday, 13 June 2021 at 10:33:06 UTC+5:30 waelmuh...@gmail.com wrote:

> Did any one understands what I mean
> ?
> في السبت، 12 يونيو 2021 في تمام الساعة 3:43:09 م UTC+3، كتب ‪wael 
> muhammed‬‏ رسالة نصها:
>
>>
>> I want to make permissions according branch id
>>  for more details 
>> 
>>
>

-- 
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/9ea27faa-b344-46d8-aa4b-3054ce90a7a3n%40googlegroups.com.


Re: CHOICES

2021-06-13 Thread Nikeet NA
from django.db.models import Sum, DecimalField
from django.db.models.functions import Cast

Model.objects.annotate(deci_con_factor=Cast('conversion_factor', 
DecimalField()).aggregate(sum=Sum('deci_con_factor')).get('sum')

You need to change your char type to decimal type , you can use CAST 
operator, you will cast you charfield to decimal field and annotate it on 
every object then use that annotated field in aggregate func. 

On Sunday, 13 June 2021 at 15:38:05 UTC+5:30 sebasti...@gmail.com wrote:

> Hello,
>
> i think this is the right answer:
>
> from django.db.models import Sum
>
> ModelName.objects.filter(field_name__isnull=True).aggregate(Sum('field_name'))#
>  returns {'field_name__sum': 1000} for example
>
>
> Am So., 13. Juni 2021 um 12:04 Uhr schrieb www.forum-gh.com <
> lada...@gmail.com>:
>
>> Hello friends 
>> please i have: conversion_fqctor = models.charfield(choices=FACTOR)
>>
>> i want to sum the conversion_factor inside my view.py how do i convert it 
>> to a decimal and use the Sum()
>>
>> -- 
>> 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/CALYpPT8_5sMsyjzvpdGZ3gBQbqiwQW7EHgZ61i4LdLQ1z38LYg%40mail.gmail.com
>>  
>> 
>> .
>>
>

-- 
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/1eff5efd-0d61-4d5d-8dca-1cbdd7aa4a85n%40googlegroups.com.


How can i start to learn django?

2021-06-13 Thread ENJOY
I am begginer in python. how can i start to learn django from begginners to 
adance. please help me.

-- 
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/9020f3b4-2c27-4082-a60e-0f5bb9ec8e96n%40googlegroups.com.


Initial data doesn't go complelely in the modelformset

2021-06-13 Thread VISHESH MANGLA
 in line 38 i have that print statement, it's output is at the top , I dont 
know why that initial data is not going into that model formset.
actually one data the PAN_ID actually went into the modelform, but the 
checkbox's "checked" didnt. You can see the html of the formset and the 
checkbox field doesnt has a checked. 


Code in paste  
https://bpa.st/FOUQ

GET 
 
Print report 
check: 
 [{'PAN_ID': '10012000', 'print_report_check': True}]






class ListFormSetView(ListView):
context_formset_name = "formset"


def get_factory_object(self):

return modelformset_factory(
self.model,
form=self.form_class,
extra=0,
)

def get_context_data(self, *, object_list=None, **kwargs):

context_formset_name = getattr(
self, "context_formset_name") 

context_data = super().get_context_data(**kwargs)


object_list = context_data["object_list"]

initial_data = self.get_initial(object_list)
context_data[context_formset_name] = self.get_factory_object()(
queryset=object_list, initial=initial_data
)

print(self.request.method , "\n", 
context_data[context_formset_name], "\n" ,initial_data )

return context_data

def get_initial(self, queryset=None):
"""Generate the initial data for the paginated queryset for the 
current page"""

if queryset is None:
queryset = []

try:
return self.initial
except AttributeError:

data = [
{**{
field_name: getattr(item, field_name)
for field_name in self.form_class._meta.fields
if hasattr(item, field_name)
}, "print_report_check":True}
for item in queryset
]

if self.request.method == "GET":
try:
userids_for_checked_boxes = 
PrintStatementData["to_download"][

PrintStatementData["list-formset-view_previous-page"]
]
except KeyError:
pass
else:
for i in data:
if i["PAN_ID"] in userids_for_checked_boxes:
i["print_report_check"] = True

return data

def get_formset_for_previous_page(self):
"""Set the `page_kwarg` 's  value to the previous page's value 
because
the formset's data needs to be compared to the previous page's data.
The `paginate_queryset` method uses self.kwargs["page_kwarg"]
to get the queryset corresponding to a page.So just to get the
initial data corresponding to the previous page through 
`self.get_form_kwargs` we first need to do this."""

PrintStatementData[
"list-formset-view_current-page"] = int(self.request.GET.get(
self.page_kwarg))

self.kwargs[self.page_kwarg] = PrintStatementData.get(
"list-formset-view_previous-page")

formset = self.get_factory_object()(**self.get_form_kwargs())

self.kwargs[self.page_kwarg] = PrintStatementData.get(
"list-formset-view_current-page")

return formset


-- 
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/f38a5d27-34bb-4346-ad0c-6ad564a55002n%40googlegroups.com.


Re: Initial data doesn't go complelely in the modelformset

2021-06-13 Thread VISHESH MANGLA
In line 58  you can see me adding  "print_report_check":True,   


my form

class PrintReportModelForm(ModelForm):
print_report_check = forms.BooleanField(widget=forms.CheckboxInput(), 
required=False)
class Meta:
fields = ["PAN_ID", "print_report_check"]
model = User
widgets = {"PAN_ID": forms.HiddenInput()}

def __init__(self,*args, **kwargs): 
super().__init__(*args, **kwargs)   
self.fields["PAN_ID"].disabled = True
 #   self.fields["print_report_check"].initial = True

def save(self, commit=True):
logger.info(" Method not meant to save anything ")
pass

On Monday, June 14, 2021 at 12:09:49 AM UTC+5:30 VISHESH MANGLA wrote:

> in line 38 i have that print statement, it's output is at the top , I dont 
> know why that initial data is not going into that model formset.
> actually one data the PAN_ID actually went into the modelform, but the 
> checkbox's "checked" didnt. You can see the html of the formset and the 
> checkbox field doesnt has a checked. 
>
>
> Code in paste  
> https://bpa.st/FOUQ
>
> GET 
>   id="id_form-TOTAL_FORMS"> value="1" id="id_form-INITIAL_FORMS"> name="form-MIN_NUM_FORMS" value="0" id="id_form-MIN_NUM_FORMS"> type="hidden" name="form-MAX_NUM_FORMS" value="1000" 
> id="id_form-MAX_NUM_FORMS">
> Print report 
> check: name="form-0-print_report_check" id="id_form-0-print_report_check"> type="hidden" name="form-0-PAN_ID" value="10012000" disabled 
> id="id_form-0-PAN_ID"> 
>  [{'PAN_ID': '10012000', 'print_report_check': True}]
>
>
>
>
>
>
> class ListFormSetView(ListView):
> context_formset_name = "formset"
>
>
> def get_factory_object(self):
>
> return modelformset_factory(
> self.model,
> form=self.form_class,
> extra=0,
> )
> 
> def get_context_data(self, *, object_list=None, **kwargs):
>
> context_formset_name = getattr(
> self, "context_formset_name") 
>
> context_data = super().get_context_data(**kwargs)
> 
>
> object_list = context_data["object_list"]
>
> initial_data = self.get_initial(object_list)
> context_data[context_formset_name] = self.get_factory_object()(
> queryset=object_list, initial=initial_data
> )
> 
> print(self.request.method , "\n", 
> context_data[context_formset_name], "\n" ,initial_data )
>
> return context_data
>
> def get_initial(self, queryset=None):
> """Generate the initial data for the paginated queryset for the 
> current page"""
>
> if queryset is None:
> queryset = []
>
> try:
> return self.initial
> except AttributeError:
>
> data = [
> {**{
> field_name: getattr(item, field_name)
> for field_name in self.form_class._meta.fields
> if hasattr(item, field_name)
> }, "print_report_check":True}
> for item in queryset
> ]
>
> if self.request.method == "GET":
> try:
> userids_for_checked_boxes = 
> PrintStatementData["to_download"][
> 
> PrintStatementData["list-formset-view_previous-page"]
> ]
> except KeyError:
> pass
> else:
> for i in data:
> if i["PAN_ID"] in userids_for_checked_boxes:
> i["print_report_check"] = True
>
> return data
>
> def get_formset_for_previous_page(self):
> """Set the `page_kwarg` 's  value to the previous page's value 
> because
> the formset's data needs to be compared to the previous page's 
> data.
> The `paginate_queryset` method uses self.kwargs["page_kwarg"]
> to get the queryset corresponding to a page.So just to get the
> initial data corresponding to the previous page through 
> `self.get_form_kwargs` we first need to do this."""
>
> PrintStatementData[
> "list-formset-view_current-page"] = int(self.request.GET.get(
> self.page_kwarg))
>
> self.kwargs[self.page_kwarg] = PrintStatementData.get(
> "list-formset-view_previous-page")
>
> formset = self.get_factory_object()(**self.get_form_kwargs())
>
> self.kwargs[self.page_kwarg] = PrintStatementData.get(
> "list-formset-view_current-page")
>
> return formset
>
>
>

-- 
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/5e95b909-3b25-4e28-a9aa-292dc09c2d59n%40googlegroups.com.


Django Project

2021-06-13 Thread Duncan Jerry
Hi guys..

Am a software developer here in Nigeria building appliations on the fly. 
currently i have a project i want to excecute (mobile app), it requires a 
backend django developer, those who want to try their hand out on something 
great.

I currently have four engineers on the job, Two frontend and Two backend 
engineer, but still need one more backend engineer to pull through the 
project and deploy. actually someone who can use django and deploy to the 
cloud at the same time.

The project is not a paid project though, but we can reach an agreement as 
a co-founder.

If this interest you, push me a mail at jeremiahaded...@gmail.com

Thanks
Jerry Duncan 

-- 
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/89cbead8-83d9-4d5c-9758-35f2ac217735n%40googlegroups.com.


Re: DEFAULT Django Session is still using File in /tmp (Can't read from directory)

2021-06-13 Thread Ryan Nowakowski
You probably don't want to use file-based sessions if you're load
balancing your application across multiple nodes.  If your session gets
created on one application node, how will the other application nodes
have access to it?  This might work if you have access to each
file-based session on every node via NFS or something like it.  Rather
than do that, I'd recommend storing your sessions in the database or
some other service like redis.

On Tue, Jun 08, 2021 at 11:26:38PM -0700, Andre Foote wrote:
> Because this is all coming from when I enabled sessions and the server 
> admin tried to implement the application on multiple nodes.
> 
> On Wednesday, April 28, 2021 at 6:41:24 PM UTC+7 Ryan Nowakowski wrote:
> 
> > What makes you think this has anything to do with Django sessions?
> >
> >
> > On April 27, 2021 11:15:57 PM CDT, Andre Foote  
> > wrote:
> >>
> >> FileNotFoundError at /admin/region/country/process_import/
> >> [Errno 2] No such file or directory: '/tmp/tmpu31qxebf'
> >> *Request Method*: POST
> >> *Request URL*: http://myurl/admin/region/country/process_import/
> >> *Django Version*: 3.0.10
> >> *Exception Type*: FileNotFoundError
> >> *Exception Value*: 
> >> [Errno 2] No such file or directory: '/tmp/tmpu31qxebf'
> >> *Exception Location*: 
> >> /usr/local/lib/python3.8/site-packages/import_export/tmp_storages.py 
> >> in open, line 29
> >> *Python Executable*: /usr/local/bin/python
> >> *Python Version*: 3.8.3
> >>
> >> I understand from the Django docs 
> >> 
> >>  that 
> >> when using File-based sessions, one must check that their "web server has 
> >> permissions to read and write to this location" (I'm not sure how/where to 
> >> enforce this, in my initial post, I tried to enforce inheritence of folder 
> >> permissions but that didn't work - any pointers would be appreciated.)
> >>
> >> However I'm using the default configuration for sessions that's supposed 
> >> to be database-backed.
> >> On Tuesday, April 27, 2021 at 9:52:03 PM UTC+2 Ryan Nowakowski wrote:
> >>
> >>>
> >>>
> >>> On April 26, 2021 11:31:24 PM CDT, Andre Foote  
> >>> wrote: 
> >>> >However, the application crashes with the error stating that it is 
> >>> >unable 
> >>> >to read the session data stored in "/tmp". 
> >>>
> >>> Please post the full error including any exception messages and the full 
> >>> Python trace back if available. 
> >>>
> >>
> 
> -- 
> 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/f4bcccbc-17b9-4507-9b17-7c477f0193aan%40googlegroups.com.

-- 
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/20210613220143.GC13579%40fattuba.com.