Re: Learning django

2018-08-07 Thread Derek
https://www.twoscoopspress.com/products/two-scoops-of-django-1-11

(Assuming you don't need the cutting-edge version and, to be honest, I'd 
think it extremely unlikely that anyone could write a book on a 
cutting-edge version of *any* software platform ... and I'd be very 
suspicious of such a book in any case)

On Sunday, 5 August 2018 18:59:48 UTC+2, Caleb Bryson wrote:
>
> Are there any books that teach django for the most recent version out 
> there? I have not been successful at finding a book with up to date info

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ebf65a5f-dfb3-4ee8-818a-ca9df59e12c4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Given source data and destination data (in json format), write a function which will validate whether source data is same as destination data and highlight the differences.

2018-08-07 Thread Derek
This is not a Django issue; try and post on a Python mailing list.

(HINT: if you want help with code, then write a function that shows what 
you have attempted.  No one else will actually write your code for you...)

On Monday, 6 August 2018 14:16:00 UTC+2, tal...@gmail.com wrote:
>
>
> please do solve this quires asap
>
>
> Given source data and destination data (in json format), write a function 
> which will validate whether
> source data is same as destination data and highlight the differences.
> Bonus: If you can validate order of data in list type values as well.
>
> E.g. below source_data and destination data are not same (highlighted 
> difference in bold )
>
> source_data = {
> "name": "Kaleigh",
> "username": "Kaleigh60",
> "email": "kalei...@gmail.com ",
> "address": {
> "street": "Myah Course",
> "suite": "Apt. 657",
> "city": "Boyerberg",
> "zipcode": "66413-8920",
> "geo": {
> "lat": "-44.6203",
> "lng": "16.7454"
> }
> },
> "website": "megane.biz",
> "friends": [
> {
> "name": "Little-Reinger",
> "catchPhrase": "Enhanced regional emulation"
> },
> {
> "name": "Big-Reinger",
> "catchPhrase": "emulation"
> }
> ],
> "Numbers": [
> 1, 2, 3, 4
> ]
> }
> destination_data = {
> "name": "Kaligh",
> "username": "Kaleigh60",
> "email": "kalei...@gmail.com ",
> "address": {
> "street": "Gold Course",
> "suite": "Apt. 657",
> "city": "Boyerberg",
> "zipcode": "66413-8920",
> "geo": {
> "lat": "-44.6203",
> "lng": "16.7454"
> }
> },
> "website": "megane.biz",
> "friends": [
> {
> "name": "Reinger",
> "catchPhrase": "Enhanced regional emulation"
> },
> {
> "name": "Big-Reinger",
> "catchPhrase": "emulation"
> }
> ],
> "Numbers": [
> 4, 2, 1, 5
> ]
> }
> E.g 2. Following data are same
> source_data = {
> "name": "Kaleigh",
> "username": "Kaleigh60",
> "email": "kalei...@gmail.com ",
> "address": {
> "street": "Myah Course",
> "suite": "Apt. 657",
> "city": "Boyerberg",
> "zipcode": "66413-8920",
> "geo": {
> "lat": "-44.6203",
> "lng": "16.7454"
> }
> }
> }
> destination_data = {
> "name": "Kaleigh",
> "address": {
> "street": "Myah Course",
> "suite": "Apt. 657",
> "city": "Boyerberg",
> "zipcode": "66413-8920",
> "geo": {
> "lat": "-44.6203",
> "lng": "16.7454"
> }
> },
> "username": "Kaleigh60",
> "email": "kalei...@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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0a54d6c3-cd67-4d0f-843e-763f9b79745f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Where can I place code to read a db table at startup to create an in memory cache?

2018-08-07 Thread B K

I would like to read a table from the database at startup time to build an 
in memory cache for fast data retrieval. 

Where is the best place to insert this code to run in django?

thx
bk

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/054b176d-075d-4bc6-af1a-b2b841ea86f5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


many to many with added attribute on template

2018-08-07 Thread rvandenbergisfap


Our challenge are as follow:

   1. Many to Many link with added attributes. 

Let me explain:

   1. We can capture the link: 
  2. 
   
But actually requires the following:

Thus captured an added attribute on the many to many relationship.

We connect to SQL SERVER 17

*Models.py*

*class *Gender(models.Model):

descr = models.CharField(max_length=128)


*class *Meta:

db_table = 

*"lkp].[gender"

**def *__str__(self):

*return *self.descr

 

 

*class *Funder_Pool(models.Model):
funder = models.ForeignKey(Funder, models.DO_NOTHING, related_name=
*'mfunder'*)
name = models.CharField(max_length=128)
descr = models.CharField(max_length=128)
fund_type = models.ForeignKey(Fund_Type, models.DO_NOTHING, related_name
=*'mfund_type'*)
ohd_course = models.ManyToManyField(OHD_Course, related_name=
*'ohd_coourse'*)
household_income_range = models.ManyToManyField(Household_Income_Range, 
related_name=*'household_income_range'*)
institution = models.ManyToManyField(Institution, 
related_name=*'institution' 
*)
gender = models.ManyToManyField(Gender, related_name=*'gender'*)
race = models.ManyToManyField(Race, related_name=*'race'*)
student_relationship = models.ForeignKey(Student_Relationship,  
models.DO_NOTHING, related_name=*'mstudent_relationship'*)
report = models.ManyToManyField(Report, related_name=*'report' *)

*class *Meta:
db_table = *"fnr].[funder_pool"*

 

 

*forms.py*

*class *fFunder_Pool(forms.ModelForm):

*class *Meta:

model = Funder_Pool


fields = [*'name'*, *'descr'*, *'fund_type'*, *'ohd_course'*, 
*'household_income_range'*, *'institution'*, *'gender'*, *'race'*, 
*'student_relationship'*, *'report'*]



*# fields = ['name', 'descr', 'gender']

*name = forms.CharField()

descr = forms.CharField()

fund_type = forms.ModelChoiceField(queryset=Fund_Type.objects.all())

ohd_course = 
forms.ModelMultipleChoiceField(queryset=OHD_Course.objects.all(), 
widget=forms.CheckboxSelectMultiple, required=*False*)

household_income_range = 
forms.ModelMultipleChoiceField(queryset=Household_Income_Range.objects.all(), 
widget=forms.CheckboxSelectMultiple, required=*False*)

institution = 
forms.ModelMultipleChoiceField(queryset=Institution.objects.all(), 
widget=forms.CheckboxSelectMultiple, required=*False*)

gender = forms.ModelMultipleChoiceField(queryset=Gender.objects.all(), 
widget=forms.CheckboxSelectMultiple(), required=*False*)

*views.py*


*#  FUNDER POOL - LIST ---
**def *funder_pool_list(request, pfunder_id):

funder_pool_list = Funder_Pool.objects.filter(funder_id=pfunder_id)

*return *render_to_response(*'funder_pool_list.html'*,{*'header'*:*"Funder 
Pool List"*, *'funder_pool_list'*:funder_pool_list, *'pfunder_id'*: pfunder_id})



*#  FUNDER POOL - EDIT ---
**def *funder_pool_edit(request, pfunder_id, pfunder_pool_id = *None*):


funder_pool_item = get_object_or_404(Funder_Pool, pk=pfunder_pool_id) *if 
*pfunder_pool_id 

*else None

if *request.method == *'POST'*:

form = fFunder_Pool(request.POST, instance=funder_pool_item)

*if *form.is_valid():

funder_pool_new = form.save(commit=*False*)

funder_pool_new.funder_id = pfunder_id

form.save()

*return *redirect(*'/funder_pool_list/' *+ str(pfunder_id))

*else*:

form = fFunder_Pool(instance = funder_pool_item)



*# Either the form was not valid, or we've just created it
**if *pfunder_pool_id:

argument_list = {*'form'*: form, *'pfunder_id'*: pfunder_id, *'id'*: 
funder_pool_item.id}

*else*:

argument_list = {*'form'*: form, *'pfunder_id'*: pfunder_id}


*return *render(request, *'funder_pool_edit.html'*, argument_list)

 

*Funder_pool_edit.py*

{% if id %}

<*form **action=**"/funder_pool_edit/{{pfunder_id}}/{{id}}" 
**method=**"post"*>

{% else %}

<*form **action=**"/funder_pool_add/{{pfunder_id}}" **method=**"post"*>

{% endif %}

<*table **border=**"0"*>

{{ form.as_table }}

  
<*input **type=**"submit" **value=**"Save!" */>
lease

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/097bf2ba-2b67-44e5-9430-105f3760b34e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Where can I place code to read a db table at startup to create an in memory cache?

2018-08-07 Thread Jason
What other alternatives have you looked at with caching before this?  How 
long is your cache lifetime, how heavy is your db load, what spikes do you 
have, what are your bottlenecks.

There are two hard things in computer science: cache invalidation, naming 
> things, and off-by-one errors.
>

https://twitter.com/codinghorror/status/506010907021828096?lang=en


-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/11bbd391-49c0-47a9-aeb0-09444af8dd6f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Docs on multiple servers/memcached daemons not clear

2018-08-07 Thread ciaran . courtney
https://docs.djangoproject.com/en/2.1/topics/cache/#memcached

When running a memcached daemon on each server, is it implicitly implied 
that each memcached daemon should be configured to listen on 0.0.0.0 
(default is 127.0.0.1) so that all Django processes can get/set in one big 
memory pool, where one daemon is local (memory overhead) and rest are on 
network (hostname/network resulution overhead)

Or is there a possibility that you may want each server to have it's own 
isolated daemon?

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e1bd5a77-cfb8-4ba6-b0e0-48d8c7a48136%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Docs on distributed memcached setup are not clear

2018-08-07 Thread ciaran . courtney
https://docs.djangoproject.com/en/2.1/topics/cache/#memcached

Particularly the multiple servers section, which does not detail if all 
memcached daemons should be configured to listen on all interfaces i.e. 
0.0.0.0

So just as a sanity check:

Scenario 1: (memcached installed naively ( i.e. listening on 
localhost:11211) on multiple ubuntu servers)
* Dev sets up her CACHE_LOCATIONS = ['server1:11211', 'server2:11211'] but 
is none the wiser that there is no interoperability between servers, 
meaning roughly 50% cache misses in totality.
* Each django process cycles through each location, only localhost is 
successful, no warning logs generated


Scenario 1: (memcached installed and configured to listen on 0.0.0.0:11211) 
on multiple ubuntu servers)
* Dev sets up her CACHE_LOCATIONS = ['server1:11211', 'server2:11211']  and 
django add/sets keys on all memcache servers successfully
* Each django process cycles through each location, adding/setting keys as 
it goes

So, am I right in thinking that the docs assume Scenario 2, but Scenario 1 
is a plausible setup, it would just mean lots of misses, but then a pro of 
no network overhead.

Am I missing something?

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2f487741-4de5-41ed-8c66-7dd565c83948%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to pass variable dates to a ORM query

2018-08-07 Thread Derek
You'll probably need to post some code snippets; what do these functions' 
signatures look like and how do they get called?

On Tuesday, 7 August 2018 03:43:01 UTC+2, Gerald Brown wrote:
>
> I have a Django/Python function that creates a Reportab PDF file based on 
> the current date.  Works GOOD. Now I want to pass any date to that function 
> and have it create a PDF based on the new date.
>
> I tried creating  another function that generates the date (yesterday) but 
> I am not able to pass the generated date to the first function.
>
> Any ideas on how to do 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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d2b30477-05a1-4c9e-9584-f1f7ea07dbda%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Docs on multiple servers/memcached daemons not clear

2018-08-07 Thread ciaran . courtney
Sorry for double post, didn't realize there was an approval 
step https://groups.google.com/forum/#!topic/django-users/EZho7Y8KSOw

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ec5bc1d2-c79b-4823-87a6-ef0e645bc715%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Where can I place code to read a db table at startup to create an in memory cache?

2018-08-07 Thread B K
Hello Jason,

This is a project dealing with Internet of Things/5G.

The plan was to cache millions of devices session information in memory for 
the frequently communicating things and to age out the infrequent things to 
the database. The in memory search would be done first, If cache hit did 
not occur, then it would goto the db for the devices that communicate 
infrequently (once a month, for example a smart meter).

The cache will be up 7x24 all the time, just like DNS.

Project is just starting, meaning that I do not have db load and spikes 
information as of yet.

I created a micro service using django, REST API, using mariadb and 
postgres to start. The micro service runs in a docker container and will 
use K8s or Docker Swarm for orchestration.

What would you recommend for an approach. I am currently just counting on 
the db (mariadb) to perform caching internally. I was about to run an 
experiment to compare my approach to just counting on the database.

thx
bk


On Tuesday, August 7, 2018 at 8:53:44 AM UTC-4, Jason wrote:
>
> What other alternatives have you looked at with caching before this?  How 
> long is your cache lifetime, how heavy is your db load, what spikes do you 
> have, what are your bottlenecks.
>
> There are two hard things in computer science: cache invalidation, naming 
>> things, and off-by-one errors.
>>
>
> https://twitter.com/codinghorror/status/506010907021828096?lang=en
>
>
>

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6f2849c0-fb43-477b-911e-08c0c60e52b1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Live Streaming Video with WebCam OpenCv Python

2018-08-07 Thread Pravin Yadav
*Hello Everyone, I'm using the Live Streaming Video through WebCam. It's
storing in .avi format. When i'm playing the Video. I'm not getting the
audio of that video. I hope that opencv does not provide the audio
features. Kindly let me know if you have any idea. Thanks,*


*Please find the below code:---*

import os.path
import numpy as np
import cv2, time
import random

def change_res(cap, width, height):
cap.set(3, width)
cap.set(4, height)

#Standard Video Dimensions Sizes
STD_DIMENSIONS = {
'480p': (640, 480),
'720p': (1280, 720),
'1080p': (1920, 1080),
'4k': (3840, 2160),
}

VIDEO_TYPE = {
'avi':cv2.VideoWriter_fourcc(*'XVID'),
'mp4':cv2.VideoWriter_fourcc(*'XVID'),
}

def get_video_type(filename):
ext = os.path.splitext(filename),
if ext in VIDEO_TYPE:
return VIDEO_TYPE[ext]
return VIDEO_TYPE['avi']

def get_dims(cap, res='480p'):
width, height = STD_DIMENSIONS['480p']
if res in STD_DIMENSIONS:
width, height = STD_DIMENSIONS[res]
change_res(cap, width, height)
return width, height

#--START LIVE VIDEO--#
random_id = random.randint(1,9)
livevideo_name = str('livevideo_'+str(random_id)+'.avi')
frames_per_second = 20.0  #..Frame Per Second
my_res = '480p'  #..Frame Size

# Capture video from camera
livevideos = '/livevideos/'+livevideo_name
cap = cv2.VideoCapture(-1)
dims = get_dims(cap, res=my_res)
video_type_cv2 = get_video_type(livevideos)

# Define the codec and create VideoWriter object
fourcc = cv2.VideoWriter_fourcc(*'XVID') # Be sure to use the lower case
out = cv2.VideoWriter(livevideos, video_type_cv2, frames_per_second, dims)
while(True):
ret, frame = cap.read()
if ret==True:
frame = cv2.flip(frame,1)
# Write the frame into the file
out.write(frame)
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break

# When everything done, release the video capture and video write objects
cap.release()
out.release()
# Closes all the frames
cv2.destroyAllWindows()

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEr6%3Ddy1tKwkvqG30uVUfXK29daHqNHr1P2JP5YQgmxskzV3XA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


django models

2018-08-07 Thread Ramandeep Kaur
My question is that how to delete models in 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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/42e646fa-af94-4250-b04a-5765e2975c3e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django ORM aggregate Sum function on foreign key

2018-08-07 Thread Kidwell Nyatsambo
Hello,
Which application / program uses vi. I would like to create a schema.sql to
use with Python.

KN

On Mon, Aug 6, 2018 at 4:08 PM, Gerald Brown  wrote:

> This is how I finally solved my problem!!!
>
> The following is a copy of my ORM statement:
>
>  Visit.objects.filter(visit_date = mydate).aggregate(total =
> Sum('visit_payment'))
> {'total': Decimal('27')}
>  This total is the total of the foreign key ids.  9 records each with a
> key of 3 = 9 x 3 = 27
>
> The way I solved this problem is to put another variable in the loop where
> I was printing the records to Reportlab PDF file and I incremented this
> variable with the value that was being printed.  What was being printed was
> the value from the look-up table so I was able to get a Sum from that.
>
> Here is the code of how I did it: vi = Visit.objects.filter(visit_date =
> mydate);  vip = 0; for v in vi:; vi_pay = str(v.visit_payment); vip +=
> int(vi_pay)
>
> Here is how the Reportlab is built: Also in the same loop as above I have
> the lines:  vi_pat = str(v.patient); pa1.drawString(x, y, str(vi_pat));
> pa1.drawString(x + 175, y, str(vi_pay))
>
> Each of these are on a separate line in my code.
>
> Hopefully this will help anyone with similar problems.
>
> On Monday, 06 August, 2018 09:35 PM, Matthew Pava wrote:
>
> You need to specify the field of the value in your ORM statement.  I don’t
> know what your field name is, but this assumes that it is “value”:
>
> aggregate(Sum(‘payment__value’))
>
>
>
> *From:* django-users@googlegroups.com [mailto:django-users@
> googlegroups.com ] *On Behalf Of *Gerald
> Brown
> *Sent:* Monday, August 6, 2018 8:29 AM
> *To:* Django users
> *Subject:* Django ORM aggregate Sum function on foreign key
>
>
>
> Greetings:
>
>
>
> I am having a problem using the above function.
>
>
>
> In my table I have a field payment that is a foreign key to a payment
> table.
>
>
>
> When I try to use aggregate(sum('payment')) it gives me the sum of the
> foreign key, not the value from the payment table.
>
> Currently I have 9 records in my test DB each one has a foreign key of 3
> so I get a sum of 27 not 2,250 that I should be getting.
>
>
>
> This table also has a foreign key to the customer table and it returns the
> customer not the foreign key number.
>
>
>
> The thought I had was to make that foreign key an integer field and then
> the user would have to enter a number instead of selecting it from a list,
> prone to operator errors,
>
>
>
> Any ideas on how I can get the correct totals using ORM.
>
>
>
> 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 post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/c47e4bb7-626c-4b07-9ab5-55d68fe4d566%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
> --
> 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 post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/3a17d4eeeb804cc89c4cda5eaca8b050%40ISS1.ISS.LOCAL
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> 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 post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/03e77e95-26b7-01e9-e11b-beca97d16176%40gmail.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to dja

Re: django models

2018-08-07 Thread Christophe Pettus


> On Aug 7, 2018, at 10:14, Ramandeep Kaur  wrote:
> 
> My question is that how to delete models in django?

Do you need to delete a model *class*, or a model *instance*?

--
-- Christophe Pettus
   x...@thebuild.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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6F27F93D-AD7C-4ACD-99A0-D940DF1BC87E%40thebuild.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django ORM aggregate Sum function on foreign key

2018-08-07 Thread Gerald Brown
vi is just a variable that I created in my code.  It is just short for 
visit.  It has NOTHING to do with the vi editor program.  My editor is 
Geany.


I am using the Django ORM to query my database.


On Wednesday, 08 August, 2018 01:45 AM, Kidwell Nyatsambo wrote:

Hello,
Which application / program uses vi. I would like to create a 
schema.sql to use with Python.


KN

On Mon, Aug 6, 2018 at 4:08 PM, Gerald Brown > wrote:


This is how I finally solved my problem!!!

The following is a copy of my ORM statement:

 Visit.objects.filter(visit_date = mydate).aggregate(total =
Sum('visit_payment'))
{'total': Decimal('27')}
 This total is the total of the foreign key ids.  9 records each
with a key of 3 = 9 x 3 = 27

The way I solved this problem is to put another variable in the
loop where I was printing the records to Reportlab PDF file and I
incremented this variable with the value that was being printed. 
What was being printed was the value from the look-up table so I
was able to get a Sum from that.

Here is the code of how I did it: vi =
Visit.objects.filter(visit_date = mydate);  vip = 0; for v in vi:;
vi_pay = str(v.visit_payment); vip += int(vi_pay)

Here is how the Reportlab is built: Also in the same loop as above
I have the lines:  vi_pat = str(v.patient); pa1.drawString(x, y,
str(vi_pat)); pa1.drawString(x + 175, y, str(vi_pay))

Each of these are on a separate line in my code.

Hopefully this will help anyone with similar problems.


On Monday, 06 August, 2018 09:35 PM, Matthew Pava wrote:


You need to specify the field of the value in your ORM
statement.  I don’t know what your field name is, but this
assumes that it is “value”:

aggregate(Sum(‘payment__value’))

*From:*django-users@googlegroups.com

[mailto:django-users@googlegroups.com
] *On Behalf Of *Gerald Brown
*Sent:* Monday, August 6, 2018 8:29 AM
*To:* Django users
*Subject:* Django ORM aggregate Sum function on foreign key

Greetings:

I am having a problem using the above function.

In my table I have a field payment that is a foreign key to a
payment table.

When I try to use aggregate(sum('payment')) it gives me the sum
of the foreign key, not the value from the payment table.

Currently I have 9 records in my test DB each one has a foreign
key of 3 so I get a sum of 27 not 2,250 that I should be getting.

This table also has a foreign key to the customer table and it
returns the customer not the foreign key number.

The thought I had was to make that foreign key an integer field
and then the user would have to enter a number instead of
selecting it from a list, prone to operator errors,

Any ideas on how I can get the correct totals using ORM.

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 post to this group, send email to
django-users@googlegroups.com .
Visit this group at https://groups.google.com/group/django-users
.
To view this discussion on the web visit

https://groups.google.com/d/msgid/django-users/c47e4bb7-626c-4b07-9ab5-55d68fe4d566%40googlegroups.com

.
For more options, visit https://groups.google.com/d/optout
.

-- 
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 post to this group, send email to
django-users@googlegroups.com .
Visit this group at https://groups.google.com/group/django-users
.
To view this discussion on the web visit

https://groups.google.com/d/msgid/django-users/3a17d4eeeb804cc89c4cda5eaca8b050%40ISS1.ISS.LOCAL

.
For more options, visit https://groups.google.com/d/optout
.


-- 
You received this message because you are subscribed to the Google

Groups "Django users" group.
To unsubscribe from this group and s

Re: django models

2018-08-07 Thread Gerald Brown
Just delete the code in models.py and run ./manage.py makemigrations and 
./manage.py migrate.



On Wednesday, 08 August, 2018 01:14 AM, Ramandeep Kaur wrote:

My question is that how to delete models in 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 post to this group, send email to django-users@googlegroups.com 
.

Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/42e646fa-af94-4250-b04a-5765e2975c3e%40googlegroups.com 
.

For more options, visit https://groups.google.com/d/optout.


--
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ebb428c7-b1cd-46e2-e139-9fe96a884353%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: django models

2018-08-07 Thread Ramandeep Kaur
when i run this ./manage.py makemigrations it gives some error. Don't know
what to do.

Traceback (most recent call last):
  File "manage.py", line 10, in 
execute_from_command_line(sys.argv)
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py",
line 353, in execute_from_command_line
utility.execute()
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py",
line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py",
line 195, in fetch_command
klass = load_command_class(app_name, subcommand)
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py",
line 39, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
  File "C:\Python27\lib\importlib\__init__.py", line 37, in import_module
__import__(name)
  File
"C:\Python27\lib\site-packages\django\core\management\commands\makemigrations.py",
line 8, in 
from django.db.migrations.autodetector import MigrationAutodetector
  File
"C:\Python27\lib\site-packages\django\db\migrations\autodetector.py", line
13, in 
from django.db.migrations.questioner import MigrationQuestioner
  File "C:\Python27\lib\site-packages\django\db\migrations\questioner.py",
line 12, in 
from .loader import MigrationLoader
  File "C:\Python27\lib\site-packages\django\db\migrations\loader.py", line
10, in 
from django.db.migrations.recorder import MigrationRecorder
  File "C:\Python27\lib\site-packages\django\db\migrations\recorder.py",
line 12, in 
class MigrationRecorder(object):
  File "C:\Python27\lib\site-packages\django\db\migrations\recorder.py",
line 26, in MigrationRecorder
class Migration(models.Model):
  File "C:\Python27\lib\site-packages\django\db\migrations\recorder.py",
line 27, in Migration
app = models.CharField(max_length=255)
  File "C:\Python27\lib\site-packages\django\db\models\fields\__init__.py",
line 1072, in __init__
super(CharField, self).__init__(*args, **kwargs)
  File "C:\Python27\lib\site-packages\django\db\models\fields\__init__.py",
line 166, in __init__
self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE
  File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 55, in
__getattr__
self._setup(name)
  File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 43, in
_setup
self._wrapped = Settings(settings_module)
  File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 120,
in __init__
raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must
not be empty.

On Wed, Aug 8, 2018 at 6:22 AM, Gerald Brown  wrote:

> Just delete the code in models.py and run ./manage.py makemigrations and
> ./manage.py migrate.
>
> On Wednesday, 08 August, 2018 01:14 AM, Ramandeep Kaur wrote:
>
> My question is that how to delete models in 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 post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/42e646fa-af94-4250-b04a-5765e2975c3e%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> 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 post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/ebb428c7-b1cd-46e2-e139-9fe96a884353%40gmail.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAL18nxmkKT9JPrvxnzQ3n1hs-KXXEUzBSX0YYqr-PP69K_PPJw%40mail.gmail.com.
For more