How to undisplay the field with empty value in django admin?

2018-03-23 Thread shawnmhy


I am currently working on django. I created 4 classes in models.py, one of 
them is ReactionMeta class. This class has 62 columns, which defined as 
below:

class Reactionsmeta(models.Model):

id = models.ForeignKey('Reactions', db_column='id', primary_key=True, 
max_length=255, on_delete=models.CASCADE)
name = models.CharField(max_length=255, blank=True, null=True)
metabolite1 = models.ForeignKey('Metabolites', db_column='metabolite1', 
blank=True, null=True,
on_delete=models.CASCADE)
stoichiometry1 = models.CharField(max_length=255, blank=True, null=True)
metabolite2 = models.ForeignKey('Metabolites', db_column='metabolite2', 
blank=True, null=True,
on_delete=models.CASCADE, related_name='+')
stoichiometry2 = models.CharField(max_length=255, blank=True, null=True)
metabolite3 = models.ForeignKey('Metabolites', db_column='metabolite3', 
blank=True, null=True,
   on_delete=models.CASCADE, related_name='+')
stoichiometry3 = models.CharField(max_length=255, blank=True, null=True)
metabolite4 = models.ForeignKey('Metabolites', db_column='metabolite4', 
blank=True, null=True,
on_delete=models.CASCADE, related_name='+')#...

Some of the reactions, may have 6 metabolites, like 2a + b + c -> 3d + e + f

however, some of reactions may only have 2 metabolites and stoichiometries, 
like a -> 2c

which means there is no value of this reaction in 
metabolite3,4,5,6...columns and stoichiometry 3,4,5,6...columns.

In that case, how can I only display the Charfield with data while 
undisplay those Charfield with no value in django-admin?

-- 
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/94300124-798c-43cb-aeaf-ec49d7ef141f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Search by entering to value in JSONField PostgreSQL

2018-03-23 Thread Michael MacIntosh

Hi,

Did you try

SomeModel.objects.filter(data__name__contains="ar")

If you want to union the results from both fields you can use a Q object:

https://docs.djangoproject.com/en/2.0/topics/db/queries/#complex-lookups-with-q-objects

And that would look something like:

complex_query = Q(data__name__contains="ar") | 
Q(data__friend_name__contains="ar)

SomeModel.objects.filter( complex_query )

Hope that helps.

Cheers!


On 3/23/2018 1:20 PM, Алексей Кузуб wrote:


Hi! I work with poorly structured data. I use EAV. But I want to 
replace EAV with jsonb in postgresql. I need to do a search by 
entering to value in json.values(). Is it possible? Is there some 
decision on Django or SQL?For example, there is the model


|class SomeModel(models.Model): data = JSONField() |

That jsons stored in rows in data field:

|{"name": "Michael", "friend_name": "Sara"} {"name": "Miranda", 
"friend_name": "Richard"} |


If I type |"ar"| in search input I want to get both rows(|"ar" in 
"Sara"|, |"ar" in "Miranda"|), |"cha"| - both rows( |"cha" in 
"Michael"|, |"ar" in "Richard"|), |"ir"| - only one (|"ir" in 
"Miranda"|), |"asdq"| - nothing. Is it possible with Django? Is it 
possible with SQL? Thank you and sorry for my English.


--
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/a3bb18e9-c513-493b-a3a8-5f8da1a40b81%40googlegroups.com 
.

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

--
This message has been scanned for viruses and dangerous content by
*E.F.A. Project* , and is believed to be 
clean.
Click here to report this message as spam. 
 



--
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/16ad14a9-da25-f494-114a-1fd115ceb04d%40linear-systems.com.
For more options, visit https://groups.google.com/d/optout.


Search by entering to value in JSONField PostgreSQL

2018-03-23 Thread Алексей Кузуб


Hi! I work with poorly structured data. I use EAV. But I want to replace 
EAV with jsonb in postgresql. I need to do a search by entering to value in 
json.values(). Is it possible? Is there some decision on Django or SQL?For 
example, there is the model

class SomeModel(models.Model):
data = JSONField()

That jsons stored in rows in data field:

{"name": "Michael", "friend_name": "Sara"}
{"name": "Miranda", "friend_name": "Richard"}

If I type "ar" in search input I want to get both rows("ar" in "Sara", "ar" 
in "Miranda"), "cha" - both rows( "cha" in "Michael", "ar" in "Richard"), 
"ir" - only one ("ir" in "Miranda"), "asdq" - nothing. Is it possible with 
Django? Is it possible with SQL? Thank you and sorry for my English.

-- 
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/a3bb18e9-c513-493b-a3a8-5f8da1a40b81%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Overriding channel-layer's group_send and group_add to add persistence

2018-03-23 Thread 'Alex' via Django users
I've just checked, and self.consistent_hash(group) returns '0' in both 
functions, so it should be connecting to the same db...

On Friday, 23 March 2018 16:05:16 UTC, Andrew Godwin wrote:
>
> I would check the connection is going to the right server/database as 
> well? But past that, I can't help you - I'd try doing some things with 
> plain aioredis to see if you can replicate it there.
>
> Andrew
>
> On Fri, Mar 23, 2018 at 9:01 AM, 'Alex' via Django users <
> django...@googlegroups.com > wrote:
>
>> Hi,
>>
>> I've used the redis-cli to get the contents of the key, and it has filled 
>> it properly, so the information is definitely in redis under that key. The 
>> issue seems to be that message = await connection.get(pers_key) always 
>> returns none. One thing I'm certain of is that it's in redis!
>>
>> Alex
>>
>> On Friday, 23 March 2018 15:58:37 UTC, Andrew Godwin wrote:
>>>
>>> It looks correct at first glance - I would insert a debugger there and 
>>> see what the Redis database contained manually at that point.
>>>
>>> Andrew
>>>
>>> On Fri, Mar 23, 2018 at 2:56 AM, 'Alex' via Django users <
>>> django...@googlegroups.com> wrote:
>>>
 I've been trying to add persistence to channel layers, such that each 
 new consumer joining a group is sent the most recent message from that 
 group, on connect. Below are my attempts. For some reason, the message in 
 the highlighted line always seems to be of type 'None'. Am I going about 
 this completely incorrectly? I'd be really grateful for any help.


 from channels_redis.core import RedisChannelLayer
 from channels.exceptions import ChannelFull
 import time


 class RedisChannelLayerGroupPersistence(RedisChannelLayer):




 async def group_send(self, group, message):
 """
 Sends a message to the entire group.
 """
 assert self.valid_group_name(group), "Group name not valid"
 # Retrieve list of all channel names
 key = self._group_key(group)
 pers_key = str(key) + "_PERS"
 async with self.connection(self.consistent_hash(group)) as 
 connection:
 # Discard old channels based on group_expiry
 await connection.zremrangebyscore(key, min=0, max=int(time.
 time()) - self.group_expiry)
 # Return current lot
 channel_names = [
 x.decode("utf8") for x in
 await connection.zrange(key, 0, -1)
 ]
 # TODO: More efficient implementation (lua script per shard?) 
  try:
 await connection.persist(pers_key)
 await connection.set(pers_key, str(message))
 print("TYPE = 
  {}".format(type(str(
 message


 for channel in channel_names:
 try:
 await self.send(channel, message)
 except ChannelFull:
 pass


 async def group_add(self, group, channel):


 """
 Adds the channel name to a group.
 """
 # Check the inputs
 assert self.valid_group_name(group), "Group name not valid"
 assert self.valid_channel_name(channel), "Channel name not 
 valid"
 # Get a connection to the right shard
 group_key = self._group_key(group)
 pers_key = str(group_key) + "_PERS"
 async with self.connection(self.consistent_hash(group)) as 
 connection:
 message = await connection.get(pers_key) #ISSUE HERE 
 -- MESSAGE IS NONE
 # Add to group sorted set with creation time as timestamp
 await connection.zadd(
 group_key,
 time.time(),
 channel,
 )
 # Set expiration to be group_expiry, since everything in
 # it at this point is guaranteed to expire before that
 try:
 await self.send(channel, str(message))
 except ChannelFull:
 pass




 await connection.expire(group_key, self.group_expiry)


 -- 
 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 post to this group, send email to django...@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/abc8747d-8d80-4ec4-a2ca-d5e91c161c08%40googlegroups.com
  
 

Re: Overriding channel-layer's group_send and group_add to add persistence

2018-03-23 Thread 'Alex' via Django users
That did occur to me, but both connect using the function below, so unless 
they're somehow referring to different groups, I'm not sure how they could 
be going to different servers/databases...
async with self.connection(self.consistent_hash(group)) as connection:


On Friday, 23 March 2018 16:05:16 UTC, Andrew Godwin wrote:
>
> I would check the connection is going to the right server/database as 
> well? But past that, I can't help you - I'd try doing some things with 
> plain aioredis to see if you can replicate it there.
>
> Andrew
>
> On Fri, Mar 23, 2018 at 9:01 AM, 'Alex' via Django users <
> django...@googlegroups.com > wrote:
>
>> Hi,
>>
>> I've used the redis-cli to get the contents of the key, and it has filled 
>> it properly, so the information is definitely in redis under that key. The 
>> issue seems to be that message = await connection.get(pers_key) always 
>> returns none. One thing I'm certain of is that it's in redis!
>>
>> Alex
>>
>> On Friday, 23 March 2018 15:58:37 UTC, Andrew Godwin wrote:
>>>
>>> It looks correct at first glance - I would insert a debugger there and 
>>> see what the Redis database contained manually at that point.
>>>
>>> Andrew
>>>
>>> On Fri, Mar 23, 2018 at 2:56 AM, 'Alex' via Django users <
>>> django...@googlegroups.com> wrote:
>>>
 I've been trying to add persistence to channel layers, such that each 
 new consumer joining a group is sent the most recent message from that 
 group, on connect. Below are my attempts. For some reason, the message in 
 the highlighted line always seems to be of type 'None'. Am I going about 
 this completely incorrectly? I'd be really grateful for any help.


 from channels_redis.core import RedisChannelLayer
 from channels.exceptions import ChannelFull
 import time


 class RedisChannelLayerGroupPersistence(RedisChannelLayer):




 async def group_send(self, group, message):
 """
 Sends a message to the entire group.
 """
 assert self.valid_group_name(group), "Group name not valid"
 # Retrieve list of all channel names
 key = self._group_key(group)
 pers_key = str(key) + "_PERS"
 async with self.connection(self.consistent_hash(group)) as 
 connection:
 # Discard old channels based on group_expiry
 await connection.zremrangebyscore(key, min=0, max=int(time.
 time()) - self.group_expiry)
 # Return current lot
 channel_names = [
 x.decode("utf8") for x in
 await connection.zrange(key, 0, -1)
 ]
 # TODO: More efficient implementation (lua script per shard?) 
  try:
 await connection.persist(pers_key)
 await connection.set(pers_key, str(message))
 print("TYPE = 
  {}".format(type(str(
 message


 for channel in channel_names:
 try:
 await self.send(channel, message)
 except ChannelFull:
 pass


 async def group_add(self, group, channel):


 """
 Adds the channel name to a group.
 """
 # Check the inputs
 assert self.valid_group_name(group), "Group name not valid"
 assert self.valid_channel_name(channel), "Channel name not 
 valid"
 # Get a connection to the right shard
 group_key = self._group_key(group)
 pers_key = str(group_key) + "_PERS"
 async with self.connection(self.consistent_hash(group)) as 
 connection:
 message = await connection.get(pers_key) #ISSUE HERE 
 -- MESSAGE IS NONE
 # Add to group sorted set with creation time as timestamp
 await connection.zadd(
 group_key,
 time.time(),
 channel,
 )
 # Set expiration to be group_expiry, since everything in
 # it at this point is guaranteed to expire before that
 try:
 await self.send(channel, str(message))
 except ChannelFull:
 pass




 await connection.expire(group_key, self.group_expiry)


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

Re: Overriding channel-layer's group_send and group_add to add persistence

2018-03-23 Thread Andrew Godwin
I would check the connection is going to the right server/database as well?
But past that, I can't help you - I'd try doing some things with plain
aioredis to see if you can replicate it there.

Andrew

On Fri, Mar 23, 2018 at 9:01 AM, 'Alex' via Django users <
django-users@googlegroups.com> wrote:

> Hi,
>
> I've used the redis-cli to get the contents of the key, and it has filled
> it properly, so the information is definitely in redis under that key. The
> issue seems to be that message = await connection.get(pers_key) always
> returns none. One thing I'm certain of is that it's in redis!
>
> Alex
>
> On Friday, 23 March 2018 15:58:37 UTC, Andrew Godwin wrote:
>>
>> It looks correct at first glance - I would insert a debugger there and
>> see what the Redis database contained manually at that point.
>>
>> Andrew
>>
>> On Fri, Mar 23, 2018 at 2:56 AM, 'Alex' via Django users <
>> django...@googlegroups.com> wrote:
>>
>>> I've been trying to add persistence to channel layers, such that each
>>> new consumer joining a group is sent the most recent message from that
>>> group, on connect. Below are my attempts. For some reason, the message in
>>> the highlighted line always seems to be of type 'None'. Am I going about
>>> this completely incorrectly? I'd be really grateful for any help.
>>>
>>>
>>> from channels_redis.core import RedisChannelLayer
>>> from channels.exceptions import ChannelFull
>>> import time
>>>
>>>
>>> class RedisChannelLayerGroupPersistence(RedisChannelLayer):
>>>
>>>
>>>
>>>
>>> async def group_send(self, group, message):
>>> """
>>> Sends a message to the entire group.
>>> """
>>> assert self.valid_group_name(group), "Group name not valid"
>>> # Retrieve list of all channel names
>>> key = self._group_key(group)
>>> pers_key = str(key) + "_PERS"
>>> async with self.connection(self.consistent_hash(group)) as
>>> connection:
>>> # Discard old channels based on group_expiry
>>> await connection.zremrangebyscore(key, min=0, max=int(time.
>>> time()) - self.group_expiry)
>>> # Return current lot
>>> channel_names = [
>>> x.decode("utf8") for x in
>>> await connection.zrange(key, 0, -1)
>>> ]
>>> # TODO: More efficient implementation (lua script per shard?)
>>>  try:
>>> await connection.persist(pers_key)
>>> await connection.set(pers_key, str(message))
>>> print("TYPE = 
>>> {}".format(type(str(message
>>>
>>>
>>> for channel in channel_names:
>>> try:
>>> await self.send(channel, message)
>>> except ChannelFull:
>>> pass
>>>
>>>
>>> async def group_add(self, group, channel):
>>>
>>>
>>> """
>>> Adds the channel name to a group.
>>> """
>>> # Check the inputs
>>> assert self.valid_group_name(group), "Group name not valid"
>>> assert self.valid_channel_name(channel), "Channel name not
>>> valid"
>>> # Get a connection to the right shard
>>> group_key = self._group_key(group)
>>> pers_key = str(group_key) + "_PERS"
>>> async with self.connection(self.consistent_hash(group)) as
>>> connection:
>>> message = await connection.get(pers_key) #ISSUE HERE
>>> -- MESSAGE IS NONE
>>> # Add to group sorted set with creation time as timestamp
>>> await connection.zadd(
>>> group_key,
>>> time.time(),
>>> channel,
>>> )
>>> # Set expiration to be group_expiry, since everything in
>>> # it at this point is guaranteed to expire before that
>>> try:
>>> await self.send(channel, str(message))
>>> except ChannelFull:
>>> pass
>>>
>>>
>>>
>>>
>>> await connection.expire(group_key, self.group_expiry)
>>>
>>>
>>> --
>>> 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 post to this group, send email to django...@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/abc8747d-8d80-4ec4-a2ca-d5e91c161c08%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

Re: channels and middlewares

2018-03-23 Thread Andrew Godwin
Check your Django version - MIDDLEWARE_CLASSES is deprecated, you should be
using the new MIDDLEWARE setting.

Andrew

On Fri, Mar 23, 2018 at 8:56 AM, Matteo Lucchesi 
wrote:

> It' possible that running a django application with channel2 ingores my
> MIDDLEWARE_CLASSES over HTTP?
>
> --
> 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/e68b23ee-5f0c-4370-9730-c56672c28cb3%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/CAFwN1uoZwTTGwhvxWnzsrcF8mwiGjSFm8sYV4%2BewezVKHYb4mQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Overriding channel-layer's group_send and group_add to add persistence

2018-03-23 Thread 'Alex' via Django users
Hi,

I've used the redis-cli to get the contents of the key, and it has filled 
it properly, so the information is definitely in redis under that key. The 
issue seems to be that message = await connection.get(pers_key) always 
returns none. One thing I'm certain of is that it's in redis!

Alex

On Friday, 23 March 2018 15:58:37 UTC, Andrew Godwin wrote:
>
> It looks correct at first glance - I would insert a debugger there and see 
> what the Redis database contained manually at that point.
>
> Andrew
>
> On Fri, Mar 23, 2018 at 2:56 AM, 'Alex' via Django users <
> django...@googlegroups.com > wrote:
>
>> I've been trying to add persistence to channel layers, such that each new 
>> consumer joining a group is sent the most recent message from that group, 
>> on connect. Below are my attempts. For some reason, the message in the 
>> highlighted line always seems to be of type 'None'. Am I going about this 
>> completely incorrectly? I'd be really grateful for any help.
>>
>>
>> from channels_redis.core import RedisChannelLayer
>> from channels.exceptions import ChannelFull
>> import time
>>
>>
>> class RedisChannelLayerGroupPersistence(RedisChannelLayer):
>>
>>
>>
>>
>> async def group_send(self, group, message):
>> """
>> Sends a message to the entire group.
>> """
>> assert self.valid_group_name(group), "Group name not valid"
>> # Retrieve list of all channel names
>> key = self._group_key(group)
>> pers_key = str(key) + "_PERS"
>> async with self.connection(self.consistent_hash(group)) as 
>> connection:
>> # Discard old channels based on group_expiry
>> await connection.zremrangebyscore(key, min=0, max=int(time.
>> time()) - self.group_expiry)
>> # Return current lot
>> channel_names = [
>> x.decode("utf8") for x in
>> await connection.zrange(key, 0, -1)
>> ]
>> # TODO: More efficient implementation (lua script per shard?) 
>>  try:
>> await connection.persist(pers_key)
>> await connection.set(pers_key, str(message))
>> print("TYPE = 
>>  {}".format(type(str(
>> message
>>
>>
>> for channel in channel_names:
>> try:
>> await self.send(channel, message)
>> except ChannelFull:
>> pass
>>
>>
>> async def group_add(self, group, channel):
>>
>>
>> """
>> Adds the channel name to a group.
>> """
>> # Check the inputs
>> assert self.valid_group_name(group), "Group name not valid"
>> assert self.valid_channel_name(channel), "Channel name not valid"
>> # Get a connection to the right shard
>> group_key = self._group_key(group)
>> pers_key = str(group_key) + "_PERS"
>> async with self.connection(self.consistent_hash(group)) as 
>> connection:
>> message = await connection.get(pers_key) #ISSUE HERE 
>> -- MESSAGE IS NONE
>> # Add to group sorted set with creation time as timestamp
>> await connection.zadd(
>> group_key,
>> time.time(),
>> channel,
>> )
>> # Set expiration to be group_expiry, since everything in
>> # it at this point is guaranteed to expire before that
>> try:
>> await self.send(channel, str(message))
>> except ChannelFull:
>> pass
>>
>>
>>
>>
>> await connection.expire(group_key, self.group_expiry)
>>
>>
>> -- 
>> 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 post to this group, send email to django...@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/abc8747d-8d80-4ec4-a2ca-d5e91c161c08%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/24613c4d-c566-4631-97cd-e858d286aadf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


channels and middlewares

2018-03-23 Thread Matteo Lucchesi
It' possible that running a django application with channel2 ingores my 
MIDDLEWARE_CLASSES over HTTP?

-- 
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/e68b23ee-5f0c-4370-9730-c56672c28cb3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Personnalisation de champ sur django

2018-03-23 Thread quentin . agren

Bonjour, 

Je veux creer un model en me servant de la classe Question comme un champ 
> du model
> Je ne sais pas comment m'y prendre
>

As-tu envisagé de créer un modèle 'Question', et de mettre une clé 
étrangère de ton modèle vers 'Question' ?
Autrement, il faudrait que tu implémentes un champ de modèle personnalisé 
en héritant de la classe 'django.db.models.Field 
'
 
comme s'est expliqué dans cette section 
 de la 
documentation. N'y ayant jamais eu recours moi-même, je ne peux 
malheureusement pas t'éclairer à ce sujet.

Quentin
 

-- 
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/fe432456-c5bf-4882-be7a-a3eb421724fd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Overriding channel-layer's group_send and group_add to add persistence

2018-03-23 Thread Andrew Godwin
It looks correct at first glance - I would insert a debugger there and see
what the Redis database contained manually at that point.

Andrew

On Fri, Mar 23, 2018 at 2:56 AM, 'Alex' via Django users <
django-users@googlegroups.com> wrote:

> I've been trying to add persistence to channel layers, such that each new
> consumer joining a group is sent the most recent message from that group,
> on connect. Below are my attempts. For some reason, the message in the
> highlighted line always seems to be of type 'None'. Am I going about this
> completely incorrectly? I'd be really grateful for any help.
>
>
> from channels_redis.core import RedisChannelLayer
> from channels.exceptions import ChannelFull
> import time
>
>
> class RedisChannelLayerGroupPersistence(RedisChannelLayer):
>
>
>
>
> async def group_send(self, group, message):
> """
> Sends a message to the entire group.
> """
> assert self.valid_group_name(group), "Group name not valid"
> # Retrieve list of all channel names
> key = self._group_key(group)
> pers_key = str(key) + "_PERS"
> async with self.connection(self.consistent_hash(group)) as
> connection:
> # Discard old channels based on group_expiry
> await connection.zremrangebyscore(key, min=0, max=int(time.
> time()) - self.group_expiry)
> # Return current lot
> channel_names = [
> x.decode("utf8") for x in
> await connection.zrange(key, 0, -1)
> ]
> # TODO: More efficient implementation (lua script per shard?)
>  try:
> await connection.persist(pers_key)
> await connection.set(pers_key, str(message))
> print("TYPE = 
> {}".format(type(str(message
>
>
> for channel in channel_names:
> try:
> await self.send(channel, message)
> except ChannelFull:
> pass
>
>
> async def group_add(self, group, channel):
>
>
> """
> Adds the channel name to a group.
> """
> # Check the inputs
> assert self.valid_group_name(group), "Group name not valid"
> assert self.valid_channel_name(channel), "Channel name not valid"
> # Get a connection to the right shard
> group_key = self._group_key(group)
> pers_key = str(group_key) + "_PERS"
> async with self.connection(self.consistent_hash(group)) as
> connection:
> message = await connection.get(pers_key) #ISSUE HERE
> -- MESSAGE IS NONE
> # Add to group sorted set with creation time as timestamp
> await connection.zadd(
> group_key,
> time.time(),
> channel,
> )
> # Set expiration to be group_expiry, since everything in
> # it at this point is guaranteed to expire before that
> try:
> await self.send(channel, str(message))
> except ChannelFull:
> pass
>
>
>
>
> await connection.expire(group_key, self.group_expiry)
>
>
> --
> 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/abc8747d-8d80-4ec4-a2ca-d5e91c161c08%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/CAFwN1up6Mq3SHnvLb6G2hvhf_cW%3DDzCZjapBLNQuBMDhJMmAWA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Probleme d'access a la base de bonnees dans le terminal window

2018-03-23 Thread ahagbes89
Bonjour 
J'ai créé un model  que j'ai nommé Person.J'ai ensuite fait ensuite les 
commandes:
- python manage.py makemigrations 
-python manage.py migrate

Mais quand je faisfrom .models import Person, ca me génere des erreurs 
et dit que la table est introuvable
Mais quand je vais l'interface administrateur,je la retrouve

-- 
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/127ec70f-068c-4639-a98e-30cdc1810fc5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django and graphs

2018-03-23 Thread Julio Biason
... and although ugly, you can render your data as a javascript object on
your template and use any graph rendering library, like jqplot.

On Fri, Mar 23, 2018 at 11:04 AM, Derek Zeng  wrote:

> What do you mean by Django extension?
> You can just use the Networkx in any django view controller and render the
> graph to svg using GraphViz. You can save the svg in database and then
> render it in a webpage.
>
> On Thursday, March 22, 2018 at 3:36:22 PM UTC-4, Mohsen wrote:
>>
>> Hi all:
>>
>> I am quite new to Django, and I am looking for Django extensions that
>> support graphs and networks. Would anybody guide me with a tutorial or some
>> hints how we may use Django together with Networkx or SNAP graph library
>> packages.
>>
>> Many thanks
>>
>> Mohsen
>>
> --
> 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/fc058693-64cf-480d-a513-0b6f35531451%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
*Julio Biason*, Sofware Engineer
*AZION*  |  Deliver. Accelerate. Protect.
Office: +55 51 3083 8101   |  Mobile: +55 51
*99907 0554*

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


Personnalisation de champ sur django

2018-03-23 Thread ahagbes89
Bonjour 
J'ai créé la classe que voici


class Question:
 
 def __init__(self,*arg,**kwarg):
  self.enonce=kwarg['enonce']
  self.point=kwarg['point']
  self.proposition=arg
  self.reponse=kwarg['reponse']

Je veux creer un model en me servant de la classe Question comme un champ 
du model
Je ne sais pas comment m'y prendre

-- 
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/216955a3-c031-46db-8dd6-15a5078eb691%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django and graphs

2018-03-23 Thread Derek Zeng
What do you mean by Django extension?
You can just use the Networkx in any django view controller and render the 
graph to svg using GraphViz. You can save the svg in database and then 
render it in a webpage.

On Thursday, March 22, 2018 at 3:36:22 PM UTC-4, Mohsen wrote:
>
> Hi all:
>
> I am quite new to Django, and I am looking for Django extensions that 
> support graphs and networks. Would anybody guide me with a tutorial or some 
> hints how we may use Django together with Networkx or SNAP graph library 
> packages.
>
> Many thanks
>
> Mohsen
>

-- 
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/fc058693-64cf-480d-a513-0b6f35531451%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Using Django Sessions

2018-03-23 Thread Derek Zeng
You can have a flag in cart class to mark if things are cleared. Then in the 
__iter__ function, check the flag before getting the keys.

If you do this you also need to add the check in add/remove and others 
accordingly.

-- 
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/a873da51-fe3b-4a75-ba40-7fe6d26fff31%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Formset created with inlineformset_factory doesn't render labels on page

2018-03-23 Thread kradem


I've got a formset:
I've got a formset:


down votefavorite 


FormSet = inlineformset_factory(
User, Profile,
fields=('mychoice',),
widgets={
'mychoice': Select(choices=CHOICES)
},
labels={
'mychoice': _('mychoices:')
}
)


Instantiated in class based DetailView:

class ProfileDisplay(DetailView):
template_name = 'profile.html'
model = User

def get(self, request, *args, **kwargs):
form = self.get_form()
profile_form = ProfileFormSet(instance=self.request.user)
return self.render_to_response(
self.get_context_data(form=form, profile_form=profile_form)
)


and shown in a template like:



{{ profile_form.management_form }}
{% for form in profile_form %}
{% for field in form %}
{{ field }}
{{ field.label_tag }}
{% endfor %}
{% endfor %}




The problem is that label is not shown on the page, I'm getting only:


mychoice true
mychoice false





-- 
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/33f4cd73-913e-4beb-8a1b-3cb5b2c60edb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Annotate with complex queries using Q

2018-03-23 Thread ravi singh
Hello Guys,

I am doing complex query using Q objects which is giving me wring 'count' 
of foreignkey objects that i am calculating using annotation. 
I can confirm the annotation result is correct when no Q object is being 
used in the query.

Is it an expected behaviour?

How can i overcome this?

Regards

-- 
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/c48d87b8-c4f1-479a-a007-6e37b1e7ad59%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


django to exe

2018-03-23 Thread Muhammad Faraz
is there any way to convert django webapp tp exe file that will run on 
localhost 

-- 
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/fbee8c37-a8b4-4f89-a4bc-22f79c7c77ee%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Overriding channel-layer's group_send and group_add to add persistence

2018-03-23 Thread 'Alex' via Django users
I've been trying to add persistence to channel layers, such that each new 
consumer joining a group is sent the most recent message from that group, 
on connect. Below are my attempts. For some reason, the message in the 
highlighted line always seems to be of type 'None'. Am I going about this 
completely incorrectly? I'd be really grateful for any help.


from channels_redis.core import RedisChannelLayer
from channels.exceptions import ChannelFull
import time


class RedisChannelLayerGroupPersistence(RedisChannelLayer):




async def group_send(self, group, message):
"""
Sends a message to the entire group.
"""
assert self.valid_group_name(group), "Group name not valid"
# Retrieve list of all channel names
key = self._group_key(group)
pers_key = str(key) + "_PERS"
async with self.connection(self.consistent_hash(group)) as 
connection:
# Discard old channels based on group_expiry
await connection.zremrangebyscore(key, min=0, max=int(time.time
()) - self.group_expiry)
# Return current lot
channel_names = [
x.decode("utf8") for x in
await connection.zrange(key, 0, -1)
]
# TODO: More efficient implementation (lua script per shard?)  try:
await connection.persist(pers_key)
await connection.set(pers_key, str(message))
print("TYPE =  
{}".format(type(str(message


for channel in channel_names:
try:
await self.send(channel, message)
except ChannelFull:
pass


async def group_add(self, group, channel):


"""
Adds the channel name to a group.
"""
# Check the inputs
assert self.valid_group_name(group), "Group name not valid"
assert self.valid_channel_name(channel), "Channel name not valid"
# Get a connection to the right shard
group_key = self._group_key(group)
pers_key = str(group_key) + "_PERS"
async with self.connection(self.consistent_hash(group)) as 
connection:
message = await connection.get(pers_key) #ISSUE HERE 
-- MESSAGE IS NONE
# Add to group sorted set with creation time as timestamp
await connection.zadd(
group_key,
time.time(),
channel,
)
# Set expiration to be group_expiry, since everything in
# it at this point is guaranteed to expire before that
try:
await self.send(channel, str(message))
except ChannelFull:
pass




await connection.expire(group_key, self.group_expiry)


-- 
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/abc8747d-8d80-4ec4-a2ca-d5e91c161c08%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.