Re: DoesNotExist behavior in db.models query.py

2017-10-23 Thread James Schneider
On Oct 23, 2017 4:06 PM, "'Aaron C. de Bruyn' via Django users" < django-users@googlegroups.com> wrote: The difference between .filter() and .get() is definitely 'by-design'. When you filter through a list of objects, you could end up with zero, one, or many objects returned. When you call .get(

Re: DoesNotExist behavior in db.models query.py

2017-10-23 Thread steve
Thank you Aaron, I started to figure this all out too as I read the docs more carefully and looked at the source code more thoughtfully. One nuance on the try/except block you propose: doesn't work as expected in the request framework because even though the except block can be stated as you pr

Re: Generating a unique 10 digit ID for each model instance

2017-10-23 Thread Jack Zhang
Hi James, First of all thank you for all your detailed replies. You have a wealth of knowledge. I took your advice and chose the separated method. I decided to use 2 letters + 8 numbers because 3 letters can render results like 'SEX' and 'FUK'. I think I got it right. Here is my code: c

Re: DoesNotExist behavior in db.models query.py

2017-10-23 Thread 'Aaron C. de Bruyn' via Django users
The difference between .filter() and .get() is definitely 'by-design'. When you filter through a list of objects, you could end up with zero, one, or many objects returned. When you call .get(), you are basically saying "I want to get exactly *one* record". If the record is not found, it is cons

Re: DoesNotExist behavior in db.models query.py

2017-10-23 Thread steve
Replying to myself here: as is often the case, the problem lies with my own source code. I was calling MODELNAME.objects.get(modelfieldname1='foo',modelfieldname2='bar') which raises the 500 when no such record exists. Turns out that calling MODELNAME.objects.filter(modelfieldname1='foo',modelf

DoesNotExist behavior in db.models query.py

2017-10-23 Thread steve
I have been tripping over the following exception DoesNotExist: INSERT_YOUR_MODEL_NAME_HERE matching query does not exist. The error is source in django 1.11.2 in db.models query.py file, in the get(self, *args, **kwargs) function, line 378 to be exact ... raise self.model.DoesNotExist(...) .

Re: Receive Websocket Message from extern task

2017-10-23 Thread Andrew Godwin
I'm not sure what you mean by "receive websockets from an external Python task" - if you want to connect out to your server using a WebSocket from Python, there are libraries that do that. Andrew On Mon, Oct 23, 2017 at 7:40 AM, 'matrix1900' via Django users < django-users@googlegroups.com> wrote

Re: Insert data into multiple models

2017-10-23 Thread mohammad k
https://docs.djangoproject.com/en/1.11/topics/signals/ On Mon, Oct 23, 2017 at 8:22 PM, mohammad k wrote: > you can use model signals > > > On Mon, Oct 23, 2017 at 4:15 PM, Mukul Mantosh > wrote: > >> I have two models (User and Employee). I want to create a new user and >> make a reference be

Re: Insert data into multiple models

2017-10-23 Thread mohammad k
you can use model signals On Mon, Oct 23, 2017 at 4:15 PM, Mukul Mantosh wrote: > I have two models (User and Employee). I want to create a new user and > make a reference between employee and user. > > > *User Table* > 1. Name > 2. E-Mail > 3. Date of Birth > 4. Contact Number > > > *Employee

Building a search form with 4 required choices, which will be inserted as arguments in an URL [warning: long question]

2017-10-23 Thread Jack Zhang
This is a semi-long question. Please let me know wherever I make a mistake. I'm building a search form with 4 required choices, 1 of the choices is a CharField with a max_length of 3. The other 3 choices are ChoiceField's. Here is a picture of what the search form looks like:

Receive Websocket Message from extern task

2017-10-23 Thread 'matrix1900' via Django users
Hello together, how can I receive websocket messages form a extern python -task. I need a example to receive websocket messages from a defined group. I can send messages to a existing Websocket Group with: * from channels import Group* and function* Group('sensor').send({'text': 'Hello, world

Insert data into multiple models

2017-10-23 Thread Mukul Mantosh
I have two models (User and Employee). I want to create a new user and make a reference between employee and user. *User Table* 1. Name 2. E-Mail 3. Date of Birth 4. Contact Number *Employee Table* 1. EmployeeID 2. Address 3. Country 4. Profile Photo 5. *user_id* *Problem Statement: *When

Re: How to store a key to a something that can be either a person or an organization?

2017-10-23 Thread James Schneider
On Oct 21, 2017 2:06 AM, "Antonis Christofides" < anto...@djangodeployment.com> wrote: Hello James, You are right that the correct term in everyday language for the superclass of organization and person is "entity". However, I didn't want to name it "entity" in the code, because, really, "entity"

Re: Generating a unique 10 digit ID for each model instance

2017-10-23 Thread Andréas Kühne
James, I agree with you - after thinking about it for another day, your solution would be the best. Regards, Andréas 2017-10-23 10:51 GMT+02:00 James Schneider : > > > On Oct 22, 2017 9:29 AM, "Andréas Kühne" > wrote: > > Hi, > > When you say "globally unique" - I am supposing you mean within

Re: I may found a bug

2017-10-23 Thread James Schneider
On Oct 21, 2017 7:12 PM, "otloal" wrote: Hi, I think I may discovered a bug in django, but I’m not sure [03:19am] The bug is this: 1. You make a ManyToManyField related the same model in wich you are creating the field [03:20am] Example: [03:21am] > > class WhatEver(models.Model): > > field = mod

Re: Generating a unique 10 digit ID for each model instance

2017-10-23 Thread James Schneider
On Oct 22, 2017 9:29 AM, "Andréas Kühne" wrote: Hi, When you say "globally unique" - I am supposing you mean within your application? What you need to do is set a field to be the primary key, see : https://docs.djangoproject.com/en/1.11/topics/db/models/# automatic-primary-key-fields Not nece

Re: Generating a unique 10 digit ID for each model instance

2017-10-23 Thread James Schneider
On Oct 22, 2017 4:36 PM, "Mark Phillips" wrote: I thought python's uuid.uuid4 guaranteed a unique value. Am I missing something? Mark >From a practical perspective, you are correct, uuid.uuid4() will create a unique value every time. There is no guarantee, though, as eventually you'll run out

Re: Generating a unique 10 digit ID for each model instance

2017-10-23 Thread James Schneider
On Oct 22, 2017 8:52 AM, "Jack Zhang" wrote: Let's say I have a model called 'Dogs'. Users can create instances of Dogs. For every Dogs instance that is created, I want to assign a globally unique ID to it. The ID will be 3 capitalized letters followed by 7 numbers. E.g. ABC1234567, POZ293019