Re: Retrieve field values from ManyToMany field in model

2017-06-25 Thread Mark Phillips
On Sun, Jun 25, 2017 at 4:20 PM, Vijay Khemlani  wrote:

> A DocumentMetaData instance may be associated with multiple documents
> and multiple metadata according to your model, so your question is
> ambiguous.
>

Sorry about the confusion. When I create a DocumentMetaData, then there is
a single row in the table that has a Document_id and MetaData_id. That is
the document title and MetaData name I am trying to get so it can be
displayed in the admin screen for that particular row in the
DocumentMetaData table. I hope that makes more sense.

>
> If you want a particular DocumentMetaData to only refer to a single
> document and a single metadata then change the ManyToManyField for a
> ForeignKey
>

That is not what I want.

>
> If you do that then you can do self.document.title and
> self.metadata.name to access those fields.
>
> On 6/25/17, Mark Phillips  wrote:
> > I have this class
> >
> > class DocumentMetaData(models.Model):
> > document = models.ManyToManyField(Document)
> > metadata = models.ManyToManyField(MetaData)
> > metadatavalue = models.ManyToManyField(MetaDataValue)
> >
> > def __str__(self):
> > return "%s - %s" % (self.document, self.metadata)
> >
> > The Document class has a field called 'title' and the Metadata class has
> a
> > field called 'name'. How do I accesses these two fields from the class
> > DocumentMetaData so the string output is something like 
> -
> > <
> > metadata.name>?
> >
> > Thanks!
> >
> > Mark
> >
> > --
> > 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/
> CAEqej2NCVAp07CvESrUnR7k61UG4b0_q5OcaemfOrh%2B77mnTdQ%40mail.gmail.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/CALn3ei0k-kV42aK%2BcT0%2By5jLGtaZOG3U2YPGT35j1nixJFxn
> 9g%40mail.gmail.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/CAEqej2Pe3rpuFb8Hy56W%3D%3DSc2j-Zk%3Dc90uAOWMibYZ5mocs2dA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Model design question

2017-06-25 Thread Mark Phillips
On Sun, Jun 25, 2017 at 6:56 PM, Constantine Covtushenko <
constantine@gmail.com> wrote:

> Hi Mark,
>
> I have some questions to you.
> 1. Does any of MetaData have predefined list of MetaDataValues?
>

No, I want to add them in real time as Documents are uploaded.


> 2. Can MetaDataValue be assigned to many Documents or it is specific to
> particular Document?
>

Yes. For example, let's say there is a MetaData called People. The values
are Mary, John, and Fred. Document 1 can have MetaData People with values
Mary and John, Document 2 can have values Fred and Mary, Document 3 can
have values Mary, John, and Fred, and Document 4 may not have MetaData
People assigned to it.


> Regards,
> Constantine C.
>
> On Sun, Jun 25, 2017 at 6:20 PM, Mark Phillips  > wrote:
>
>> I have a class Document that uploads a document. I have a class MetaData
>> that is the name for some metadata for that document. Since a MetaData can
>> have one or more values, there is another class called MetaDataValue that
>> has a ForeignKey to MetaData. Finally, there is a class
>> DocumentMetaDataValue that links these three tables. It almost works...but
>> in the Admin screen when I want to add something to the DocumentMetaData
>> class I can select one or more documents from a drop down list (good!), and
>> one or more Metadata from a dropdown list (good), and I can select one or
>> more MetaDataValues from a drop down list (good). However, the bad news is
>> that the relationship between the MetaData and MetaDataValue is not
>> preserved.
>>
>> For example, say I have MetaData 'people' with values John, Mark,
>> Allison, and 'events' with values birthday, wedding, funeral. When I add a
>> DocumentMetaData, I want to select 'people' from the MetaData dropdown, and
>> then only the MetaDataValues for 'people' should be displayed in the
>> MetaDataValues dropdown. Instead, what I get is all the MetaDataValues
>> regardless of the associated MetaData, and I can add a MetaDataValue of
>> John to a document under the Metadata label of 'events'. What am I missing
>> in the relationship between the MetaDataValues class and the MetaData class?
>>
>> These are my classes. I have removed some of the extraneous fields and
>> methods in the classes for clarity.
>>
>> class MetaData(models.Model):
>> metadata_id = models.AutoField(primary_key = True)
>> name = models.CharField('metadata name', max_length=200)
>>
>> class MetaDataValue(models.Model):
>> metadata = models.ForeignKey(MetaData, on_delete=models.CASCADE,)
>> value = models.CharField('value', max_length=200)
>>
>> class Document(models.Model):
>> document_id = models.AutoField(primary_key=True)
>> title = models.CharField('title', max_length=200)
>>
>> class DocumentMetaData(models.Model):
>> document = models.ManyToManyField(Document)
>> metadata = models.ManyToManyField(MetaData)
>> metadatavalue = models.ManyToManyField(MetaDataValue)
>>
>> 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/ms
>> gid/django-users/CAEqej2PO2bMW%2BZ%3DPJVy66%3DWspm6E7zetGrYH
>> yxjg-9iOjBmzaQ%40mail.gmail.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> Sincerely yours,
> Constantine C
>
> --
> 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/CAK52boVERbCZW1%3D0F7G_f%3DFyUtQtEBVeyuFkNQVpxs7%
> 3D91Gb3Q%40mail.gmail.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.go

Re: Model design question

2017-06-25 Thread Constantine Covtushenko
Hi Mark,

I have some questions to you.
1. Does any of MetaData have predefined list of MetaDataValues?
2. Can MetaDataValue be assigned to many Documents or it is specific to
particular Document?

Regards,
Constantine C.

On Sun, Jun 25, 2017 at 6:20 PM, Mark Phillips 
wrote:

> I have a class Document that uploads a document. I have a class MetaData
> that is the name for some metadata for that document. Since a MetaData can
> have one or more values, there is another class called MetaDataValue that
> has a ForeignKey to MetaData. Finally, there is a class
> DocumentMetaDataValue that links these three tables. It almost works...but
> in the Admin screen when I want to add something to the DocumentMetaData
> class I can select one or more documents from a drop down list (good!), and
> one or more Metadata from a dropdown list (good), and I can select one or
> more MetaDataValues from a drop down list (good). However, the bad news is
> that the relationship between the MetaData and MetaDataValue is not
> preserved.
>
> For example, say I have MetaData 'people' with values John, Mark, Allison,
> and 'events' with values birthday, wedding, funeral. When I add a
> DocumentMetaData, I want to select 'people' from the MetaData dropdown, and
> then only the MetaDataValues for 'people' should be displayed in the
> MetaDataValues dropdown. Instead, what I get is all the MetaDataValues
> regardless of the associated MetaData, and I can add a MetaDataValue of
> John to a document under the Metadata label of 'events'. What am I missing
> in the relationship between the MetaDataValues class and the MetaData class?
>
> These are my classes. I have removed some of the extraneous fields and
> methods in the classes for clarity.
>
> class MetaData(models.Model):
> metadata_id = models.AutoField(primary_key = True)
> name = models.CharField('metadata name', max_length=200)
>
> class MetaDataValue(models.Model):
> metadata = models.ForeignKey(MetaData, on_delete=models.CASCADE,)
> value = models.CharField('value', max_length=200)
>
> class Document(models.Model):
> document_id = models.AutoField(primary_key=True)
> title = models.CharField('title', max_length=200)
>
> class DocumentMetaData(models.Model):
> document = models.ManyToManyField(Document)
> metadata = models.ManyToManyField(MetaData)
> metadatavalue = models.ManyToManyField(MetaDataValue)
>
> 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/CAEqej2PO2bMW%2BZ%3DPJVy66%3DWspm6E7zetGrYHyxjg-
> 9iOjBmzaQ%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sincerely yours,
Constantine C

-- 
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/CAK52boVERbCZW1%3D0F7G_f%3DFyUtQtEBVeyuFkNQVpxs7%3D91Gb3Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Retrieve field values from ManyToMany field in model

2017-06-25 Thread Vijay Khemlani
A DocumentMetaData instance may be associated with multiple documents
and multiple metadata according to your model, so your question is
ambiguous.

If you want a particular DocumentMetaData to only refer to a single
document and a single metadata then change the ManyToManyField for a
ForeignKey

If you do that then you can do self.document.title and
self.metadata.name to access those fields.

On 6/25/17, Mark Phillips  wrote:
> I have this class
>
> class DocumentMetaData(models.Model):
> document = models.ManyToManyField(Document)
> metadata = models.ManyToManyField(MetaData)
> metadatavalue = models.ManyToManyField(MetaDataValue)
>
> def __str__(self):
> return "%s - %s" % (self.document, self.metadata)
>
> The Document class has a field called 'title' and the Metadata class has a
> field called 'name'. How do I accesses these two fields from the class
> DocumentMetaData so the string output is something like  -
> <
> metadata.name>?
>
> Thanks!
>
> Mark
>
> --
> 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/CAEqej2NCVAp07CvESrUnR7k61UG4b0_q5OcaemfOrh%2B77mnTdQ%40mail.gmail.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/CALn3ei0k-kV42aK%2BcT0%2By5jLGtaZOG3U2YPGT35j1nixJFxn9g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Model design question

2017-06-25 Thread Mark Phillips
I have a class Document that uploads a document. I have a class MetaData
that is the name for some metadata for that document. Since a MetaData can
have one or more values, there is another class called MetaDataValue that
has a ForeignKey to MetaData. Finally, there is a class
DocumentMetaDataValue that links these three tables. It almost works...but
in the Admin screen when I want to add something to the DocumentMetaData
class I can select one or more documents from a drop down list (good!), and
one or more Metadata from a dropdown list (good), and I can select one or
more MetaDataValues from a drop down list (good). However, the bad news is
that the relationship between the MetaData and MetaDataValue is not
preserved.

For example, say I have MetaData 'people' with values John, Mark, Allison,
and 'events' with values birthday, wedding, funeral. When I add a
DocumentMetaData, I want to select 'people' from the MetaData dropdown, and
then only the MetaDataValues for 'people' should be displayed in the
MetaDataValues dropdown. Instead, what I get is all the MetaDataValues
regardless of the associated MetaData, and I can add a MetaDataValue of
John to a document under the Metadata label of 'events'. What am I missing
in the relationship between the MetaDataValues class and the MetaData class?

These are my classes. I have removed some of the extraneous fields and
methods in the classes for clarity.

class MetaData(models.Model):
metadata_id = models.AutoField(primary_key = True)
name = models.CharField('metadata name', max_length=200)

class MetaDataValue(models.Model):
metadata = models.ForeignKey(MetaData, on_delete=models.CASCADE,)
value = models.CharField('value', max_length=200)

class Document(models.Model):
document_id = models.AutoField(primary_key=True)
title = models.CharField('title', max_length=200)

class DocumentMetaData(models.Model):
document = models.ManyToManyField(Document)
metadata = models.ManyToManyField(MetaData)
metadatavalue = models.ManyToManyField(MetaDataValue)

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/CAEqej2PO2bMW%2BZ%3DPJVy66%3DWspm6E7zetGrYHyxjg-9iOjBmzaQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Retrieve field values from ManyToMany field in model

2017-06-25 Thread Mark Phillips
I have this class

class DocumentMetaData(models.Model):
document = models.ManyToManyField(Document)
metadata = models.ManyToManyField(MetaData)
metadatavalue = models.ManyToManyField(MetaDataValue)

def __str__(self):
return "%s - %s" % (self.document, self.metadata)

The Document class has a field called 'title' and the Metadata class has a
field called 'name'. How do I accesses these two fields from the class
DocumentMetaData so the string output is something like  - <
metadata.name>?

Thanks!

Mark

-- 
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/CAEqej2NCVAp07CvESrUnR7k61UG4b0_q5OcaemfOrh%2B77mnTdQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Websocket, an existing connection was forcibly closed by the remote host. django-channels

2017-06-25 Thread Mike Johnson Jr


So I'm getting the error as described in the title of this post.

I'm following this tutorial: 
https://gearheart.io/blog/creating-a-chat-with-django-channels/

Here's the full traceback:

In [1]: import websocket
In [2]: ws = websocket.WebSocket()
In [3]: 
ws.connect("ws://localhost:8000")---
error Traceback (most recent call 
last) in ()> 1 
ws.connect("ws://localhost:8000")

c:\Python27\lib\site-packages\websocket\_core.pyc in connect(self, url, 
**options)
212
213 try:--> 214 self.handshake_response = 
handshake(self.sock, *addrs, **options)
215 self.connected = True
216 except:

c:\Python27\lib\site-packages\websocket\_handshake.pyc in handshake(sock, 
hostname, por
t, resource, **options)
 67 dump("request header", header_str)
 68---> 69 status, resp = _get_resp_headers(sock)
 70 success, subproto = _validate(resp, key, 
options.get("subprotocols"))
 71 if not success:

c:\Python27\lib\site-packages\websocket\_handshake.pyc in 
_get_resp_headers(sock, succe
ss_status)
125
126 def _get_resp_headers(sock, success_status=101):--> 127 status, 
resp_headers = read_headers(sock)
128 if status != success_status:
129 raise WebSocketBadStatusException("Handshake status %d", status)

c:\Python27\lib\site-packages\websocket\_http.pyc in read_headers(sock)
224
225 while True:--> 226 line = recv_line(sock)
227 line = line.decode('utf-8').strip()
228 if not line:

c:\Python27\lib\site-packages\websocket\_socket.pyc in recv_line(sock)
 99 line = []
100 while True:--> 101 c = recv(sock, 1)
102 line.append(c)
103 if c == six.b("\n"):

c:\Python27\lib\site-packages\websocket\_socket.pyc in recv(sock, bufsize)
 78
 79 try:---> 80 bytes_ = sock.recv(bufsize)
 81 except socket.timeout as e:
 82 message = extract_err_message(e)

error: [Errno 10054] An existing connection was forcibly closed by the remote 
host

I have redis running, manage.py runserver running, and I'm using 
django-channels. This is my first time working with websockets. Can anyone 
help out and let me know what's wrong?
python  django 
 websocket 
 redis 
 django-channels 


-- 
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/878e70cd-4e39-4b1f-87bd-da7ddb03605b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.