Re: Login

2017-12-04 Thread Martin Peveri
Check this: 

https://simpleisbetterthancomplex.com/tutorial/2016/06/27/how-to-use-djangos-built-in-login-system.html

El lunes, 4 de diciembre de 2017, 14:49:32 (UTC-3), chaitanya.creator 
escribió:
>
> Hi 
>  i am new users django .please help in making a login system using django 
> Thank you 
>
>

-- 
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/a4e6e3ef-d318-4ccd-8d1f-ae94540cf52d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Update dict JsonField Postgresql

2017-03-27 Thread Martin Peveri
Hi everyone, I have a model model like this:


class ItemCampaign(models.Model):

   campaign = models.ForeignKey(
   Campaign, related_name="itemscampaign", verbose_name="Item campaña"
   )
   data = JSONField(default=dict)

   def __str__(self):
   return self.campaign.name

The field data, contains this list dict, for example:

[{'number': '1160188479', 'id': 0, 'content': 'hello', 'processed': False}, 
{'number': '1160188479', 'id': 1, 'content': 'hello', 'processed': False}, {
'number': '1160188479', 'id': 2, 'content': 'hello', 'processed': False}, {
'number': '1162341721', 'id': 3, 'content': 'hello', 'processed': False}, {
'number': '1162341721', 'id': 4, 'content': 'hello', 'processed': False}, {
'number': '1162341721', 'id': 5, 'content': 'hello', 'processed': False}}

I wish make is update one dict of this list:

objectitem.data[0]['processed'] =True
objectitem.save()


But not working.

Any Idea?.

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/92a4e1aa-6d02-4689-bea1-573c4b7720f7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Update dict JsonField Postgresql

2017-03-27 Thread Martin Peveri
Hi  Melvyn, With "not working", I mean that it does nothing. For example

This line

>>> objectitem.data[0]['processed'] = True

It does not return any errors

This line:

>>> objectitem.save()

Neither

So when I'm going to get the record back, it returns me the same.

>>> objectitem.data[0]
>>> False

I would have to return True. I explain? My English is not very good.

You can explain a little more this: "Django's JSONEncoder only accepts 
dicts as outermost structure."

I am inserting a list of dicts. For example:

>>> Model.objects.create(data={[..my dicts ]}

That's wrong?

Thanks!


El lunes, 27 de marzo de 2017, 11:52:37 (UTC-2), Melvyn Sopacua escribió:
>
> On Monday 27 March 2017 05:56:34 Martin Peveri wrote:
>
>  
>
> > But not working.
>
> > 
>
> > Any Idea?.
>
>  
>
> Plenty. But start by defining "not working". Not trying to be snarky, but 
> there are a lot of moving parts here and it's anybody's guess at this point 
> what part is causing the problem. We don't even know how you determined 
> it's not working (get an exception, value isn't changed, save doesn't get 
> called, form errors ... ).
>
>  
>
> Here's my shot in the dark:
>
> Django's JSONEncoder only accepts dicts as outermost structure.
>
> -- 
>
> Melvyn Sopacua
>

-- 
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/566e1231-b643-49f7-88e1-0abef9991c71%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Update dict JsonField Postgresql

2017-03-27 Thread Martin Peveri
json.dumps return this (For example, the field contains 50k of records):

[{'number': '1160188479', 'id': 0, 'content': 'hello', 'processed': False}, 
{'number': '1160188479', 'id': 1, 'content': 'hello', 'processed': False}, {
'number': '1160188479', 'id': 2,'content': 'hello', 'processed': False}, {
'number': '1162341721', 'id': 3, 'content': 'hello', 'processed': False}, {
'number': '1162341721', 'id': 4, 'content': 'hello', 'processed':False}, {
'number': '1162341721', 'id': 5, 'content': 'hello', 'processed': False}]



El lunes, 27 de marzo de 2017, 11:28:53 (UTC-3), Melvyn Sopacua escribió:
>
> Hi Martin,
>
>  
>
> On Monday 27 March 2017 07:05:38 Martin Peveri wrote:
>
> > Hi Melvyn, With "not working", I mean that it does nothing. For
>
> > example
>
> > 
>
> > This line
>
> > 
>
> > >>> objectitem.data[0]['processed'] = True
>
> > 
>
> > It does not return any errors
>
> > 
>
> > This line:
>
> > >>> objectitem.save()
>
> > 
>
> > Neither
>
> > 
>
> > So when I'm going to get the record back, it returns me the same.
>
> > 
>
> > >>> objectitem.data[0]
>
> > >>> False
>
> > 
>
> > I would have to return True.
>
>  
>
> Is this really how you typed it? Because objectitem.data[0] should be a 
> dict or list, but not a boolean.
>
> Could you show the output of:
>
>  
>
> json.dumps(objectitem.data)
>
>  
>
>  
>
> > I explain? My English is not very good.
>
> > 
>
> > You can explain a little more this: "Django's JSONEncoder only accepts
>
> > dicts as outermost structure."
>
>  
>
> I'm not sure it is used for assigning data to the json field. It is used 
> to form a django.http.JSONResponse 
> <https://docs.djangoproject.com/en/1.10/ref/request-response/#jsonresponse-objects>
>  
> and to serialize data to JSON, so that was a guess.
>
>  
>
> > I am inserting a list of dicts. For example:
>
> > >>> Model.objects.create(data={[..my dicts ]}
>
> > 
>
> > That's wrong?
>
>  
>
> Not sure, but as you typed it, it's a set, not a dict (there is no 
> 'key':), so if python thinks any of the lists are identifcal, it'll be 
> missing.
>
>  
>
>  
>
> -- 
>
> Melvyn Sopacua
>

-- 
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/49f63d83-7582-4b59-be71-5c35031fd1d3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Update dict JsonField Postgresql

2017-03-27 Thread Martin Peveri
Perfect!! This code works:

data = objectitem.data

data[0]['processed'] = True

objectitem.data = data

objectitem.save()

A last query that is not related to the insertion, but to the query.

If I want to get only records processed in True as I have to do?

This does not work, I get all the records:

objectitem.filter(data__contains=[{'processed': True}])

Thanks!!!



El lunes, 27 de marzo de 2017, 14:29:13 (UTC-3), Melvyn Sopacua escribió:
>
> Hi,
>
>  
>
> On Monday 27 March 2017 08:50:04 Martin Peveri wrote:
>
>  
>
> Totally forgot about this gotcha:
>
>  
>
> > > > >>> objectitem.data[0]['processed'] = True
>
>  
>
> That won't work.
>
> objectitem.data is a reference to a list of dicts
>
> changing something inside, doesn't signal the model that it's data has 
> changed, as the reference doesn't change.
>
>  
>
> You need to manipulate the data as it's own structure, then assign it:
>
>  
>
> data = objectitem.data
>
> data[0]['processed'] = True
>
> objectitem.data = data
>
> objectitem.save()
>
>  
>
> If the above don't work:
>
> objecitem.save(force_update=True, update_fields=('data',))
>
>  
>
>  
>
> -- 
>
> Melvyn Sopacua
>

-- 
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/6951c970-5ee8-496e-a965-73da5ec3600f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Update dict JsonField Postgresql

2017-03-28 Thread Martin Peveri
It does not work :(

With ArrayField Will I be able to filter the content of the field?. For 
example, if i have one record and in the field data a list of dict with 
50k. Can I filter it?. That is to say, to bring only in the array the 
records with 'processed' true.

Thanks! 

El martes, 28 de marzo de 2017, 6:58:51 (UTC-3), Melvyn Sopacua escribió:
>
> On Monday 27 March 2017 15:03:17 Martin Peveri wrote:
>
> > Perfect!! This code works:
>
> > 
>
> > data = objectitem.data
>
> > 
>
> > data[0]['processed'] = True
>
> > 
>
> > objectitem.data = data
>
> > 
>
> > objectitem.save()
>
> > 
>
> > A last query that is not related to the insertion, but to the query.
>
> > 
>
> > If I want to get only records processed in True as I have to do?
>
> > 
>
> > This does not work, I get all the records:
>
> > 
>
> > objectitem.filter(data__contains=[{'processed': True}])
>
>  
>
> Looking at your data model, you should probably make data an ArrayField of 
> JSONFields...
>
> This would simplify things quite a bit.
>
>  
>
> That said, I would try data__contains={'processed': True}, but if that 
> doesn't work, your problem is that your outer structure is a list, not an 
> object, making filtering a lot harder.
>
>  
>
> -- 
>
> Melvyn Sopacua
>

-- 
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/403307f0-2cf6-4e73-b979-558c279a1450%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Filter list dict in JsonField Postgres

2017-04-03 Thread Martin Peveri
Hi, I have this model:

class ItemCampaign(models.Model):

   campaign = models.ForeignKey(
   Campaign, related_name="itemscampaign", verbose_name="Item campaña"
   )
   data = JSONField(default=dict)

   def __str__(self):
   return self.campaign.name 

With a record with this data: 

[{'number': '1160188479', 'id': 0, 'content': 'hello', 'processed': True}, {
'number': '1160188479', 'id': 1, 'content': 'hello', 'processed': False}, {
'number': '1160188479', 'id': 2,'content': 'hello', 'processed': False}, {
'number': '1162341721', 'id': 3, 'content': 'hello', 'processed': False}, {
'number': '1162341721', 'id': 4, 'content': 'hello', 'processed':False}, {
'number': '1162341721', 'id': 5, 'content': 'hello', 'processed': False}]

I want filter this list dict, like this:

c.itemscampaign.filter(data__processed=True)

But not work. That does not give me back anything.

The content type of data is:

>>> type(c.itemscampaign.all()[0].data)


I understand that it has to be a dict, but how can I insert many 
dictionaries in the field, as I have in my data if it is not in a list?

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/27feeb2b-6b41-4d3a-b771-08653a99d9c4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.