Re: simple django application since im a beginner I'm unable to doit..

2018-06-27 Thread 'Anthony Flury' via Django users

On 25/06/18 15:57, mr.sathee...@gmail.com wrote:
I want to know the IP is malicious or not by simple web application 
since I'm a beginner I unable to do it. help me
Define malicious ? You would need to look  at how it is normally defined 
(normally companies use blacklists of IP address ranges - mainly based 
on those ranges being used in spam attacks) - those blacklists will be 
updated often.


Without a blacklist of some form you can't just look at an IP address 
and decide that it is 'malicious' - when you register for an IP-range 
they don't ask if you plan to use the range for hacking.



--
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/40926567-952b-449b-85b2-e7e91ab86b82%40googlegroups.com 
.

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



--
--
Anthony Flury
email : *anthony.fl...@btinternet.com*
Twitter : *@TonyFlury *

--
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/6cdecd4b-1efc-1405-9fc6-0a9f33797ee2%40btinternet.com.
For more options, visit https://groups.google.com/d/optout.


Can't access my django runserver

2018-06-27 Thread Umar Kambala
Please after going through my django polls, now if I runserver I gets this
error

'APP_DIRS' : True,
SyntaxError: invalid syntax.
Please wat do I do?

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


Deploy on Heroku

2018-06-27 Thread Elias Coutinho
Good Morning,

Following the deploy model of this tutorial 
,
 
I was not successful.

Below the traceback of the terminal and then the heroku logs.


Where did I go wrong? I did not identify what the message meant.





-- 
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/1c90951d-8a49-40be-b100-a584a19df446%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


better way to create a dictionary in Django model?

2018-06-27 Thread prateek gupta
Hi All,

I am using Django 2.0.6 with Python 3.6 and MySql and created a model which 
maps the db tables to django.
In my database, I have a column 'config' of type json.
This column stores the data in a dictionary format like below- 
{"user_id": "a...@example.com", "password": "xyz"}
I need to make it editable via the Django like below screen shot-



I need your suggestion - what is the best way to achieve this?
I found a useful link for this purpose -
how-to-store-a-dictionary-on-a-django-model 

 but 
want to take your valuable guidance before proceeding so that I can 
implement with best practices.

-- 
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/eeaba88f-136a-4e03-9599-b564a596bdf8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Deploy on Heroku

2018-06-27 Thread Fabio C. Barrionuevo da Luz
The error is explicitly here:

django.core.exceptions.ImproperlyConfigured: sets the REDIS_URL
environment variable


that is, you have not enabled the Redis plugin in Heroku.

As shown in the cookiecutter-django tutorial, it's just you, inside the
folder of your project, run:

heroku addons:create heroku-redis:hobby-dev





2018-06-27 9:03 GMT-03:00 Elias Coutinho :

> Good Morning,
>
> Following the deploy model of this tutorial
> ,
> I was not successful.
>
> Below the traceback of the terminal and then the heroku logs.
>
>
> Where did I go wrong? I did not identify what the message meant.
>
>
> 
>
>
> 
>
> --
> 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/1c90951d-8a49-40be-b100-a584a19df446%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Fábio C. Barrionuevo da Luz
Palmas - Tocantins - Brasil - América do Sul

http://pythonclub.com.br/

Blog colaborativo sobre Python e tecnologias Relacionadas, mantido
totalmente no https://github.com/pythonclub/pythonclub.github.io .

Todos são livres para publicar. É só fazer fork, escrever sua postagem e
mandar o pull-request. Leia mais sobre como publicar em README.md e
contributing.md.
Regra básica de postagem:
"Você" acha interessante? É útil para "você"? Pode ser utilizado com Python
ou é útil para quem usa Python? Está esperando o que? Publica logo, que
estou louco para ler...

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


Re: Can't access my django runserver

2018-06-27 Thread Joshua Kayode
I think you need to give more details, we are all ready to help!

On Jun 27, 2018 10:41, "Umar Kambala"  wrote:

> Please after going through my django polls, now if I runserver I gets this
> error
>
> 'APP_DIRS' : True,
> SyntaxError: invalid syntax.
> Please wat do I do?
>
> --
> 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/CAPkbFbagk%2B4m5Ze3THLfAABBx8fVENHG7QqunA
> 81pYnnUwXJhQ%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/CAEL9fCHT%2BHwLkKa4dewj-Kso5kvSi%3DT1So8Av63WtBkighZf8Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Django's cache framework problem

2018-06-27 Thread 林挺滨
When I use cache framework api to cache a model instance,  @cached_property 
of the instance doesn't work. Why?

-- 
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/5b27fa47-c712-460f-a421-1eb1d41c764e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Newbie : Object copy - weird error :-)

2018-06-27 Thread Julio Biason
Hi Mikael,

The problem is happening because of this: __init__() takes from 1 to 2
positional arguments but 11 were given

On your new __init__(), you added just 2 parameters: `self` and `source`.
But you overwrote the default `models.Model` init, which receives way more
parameters (the original signature for this function is `__init__(self,
*args, **kwargs)`).

What are you actually trying to achieve with this?

On Tue, Jun 26, 2018 at 1:17 PM,  wrote:

> Hi all :-)
>
> I'd like to archive some data.
>
> I did that :
>
> class AbstractDataModel(models.Model):
>
> xxx
>
>
> class Meta:
> abstract = True
>
>
> def __iter__(self):
>
> return iter([self.xxx, self.yyy, self.zzz, self.aaa,
> self.qqq, self.mode_bbb])
>
>
> class DataModel(AbstractDataModel):
>
>
> pass
>
>
> class DataModelArchive(AbstractDataModel):
> # https://stackoverflow.com/questions/21699707/python-how-
> to-copy-all-attibutes-from-base-class-to-derived-one
> def __init__(self, source=None):
> if source is not None:
> self.__dict__.update(source.__dict__)
>
>
>
> But when I want to access data in DataModelArchive, like
> DataModelArchive.objects.all() for example,
> I get
>
>
> Traceback (most recent call last):
>   File "/home/.../tests.py", line 1090, in test_archive
> print(DataModelArchive.objects.all())
>   File "/home/.../venv/lib/python3.6/site-packages/django/db/
> models/query.py", line 248, in __repr__
> data = list(self[:REPR_OUTPUT_SIZE + 1])
>   File "/home/.../venv/lib/python3.6/site-packages/django/db/
> models/query.py", line 272, in __iter__
> self._fetch_all()
>   File "/home/.../venv/lib/python3.6/site-packages/django/db/
> models/query.py", line 1179, in _fetch_all
> self._result_cache = list(self._iterable_class(self))
>   File "/home/.../venv/lib/python3.6/site-packages/django/db/
> models/query.py", line 63, in __iter__
> obj = model_cls.from_db(db, init_list, row[model_fields_start:model_
> fields_end])
>   File "/home/.../lib/python3.6/site-packages/django/db/models/base.py",
> line 507, in from_db
> new = cls(*values)
> TypeError: __init__() takes from 1 to 2 positional arguments but 11 were
> given
>
>
>
> What am I doing wrong ?
>
> Thx
> ;-)
>
> --
> 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/ac3a7a8f-f878-48b3-943a-eb47f6b03e7e%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/CAEM7gE2y%3DQHEJdbwUMbhmxDnY8%2BEHSVdUKUJtgbGTX2UgoWKSA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django's cache framework problem

2018-06-27 Thread 赖信桃
Show me your code snippet.

林挺滨 于2018年6月27日周三 下午8:44写道:

> When I use cache framework api to cache a model instance,  @cached_property
> of the instance doesn't work. Why?
>
> --
> 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/5b27fa47-c712-460f-a421-1eb1d41c764e%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/CAMv51WQMrueCfWoBV3a0Djr7QhL3mqXcg_Ak5yNt75%3DP2Vy4WA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: better way to create a dictionary in Django model?

2018-06-27 Thread Yehor Smoliakov
Better way it to use packages like this
https://github.com/lazybird/django-solo

On 27 June 2018 at 15:18, prateek gupta  wrote:

> Hi All,
>
> I am using Django 2.0.6 with Python 3.6 and MySql and created a model
> which maps the db tables to django.
> In my database, I have a column 'config' of type json.
> This column stores the data in a dictionary format like below-
> {"user_id": "a...@example.com", "password": "xyz"}
> I need to make it editable via the Django like below screen shot-
>
>
> 
>
> I need your suggestion - what is the best way to achieve this?
> I found a useful link for this purpose -how-to-store-a-dictionary-on-
> a-django-model
> 
>  but
> want to take your valuable guidance before proceeding so that I can
> implement with best practices.
>
> --
> 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/eeaba88f-136a-4e03-9599-b564a596bdf8%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Kind Regards, Yehor Smoliakov.

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


Re: better way to create a dictionary in Django model?

2018-06-27 Thread prateek gupta
It has some limit- The configuration object can only be changed, there's no 
link for "add" (1)

On Wednesday, June 27, 2018 at 6:41:41 PM UTC+5:30, Egor Smolyakov wrote:
>
> Better way it to use packages like this 
> https://github.com/lazybird/django-solo
>
> On 27 June 2018 at 15:18, prateek gupta > 
> wrote:
>
>> Hi All,
>>
>> I am using Django 2.0.6 with Python 3.6 and MySql and created a model 
>> which maps the db tables to django.
>> In my database, I have a column 'config' of type json.
>> This column stores the data in a dictionary format like below- 
>> {"user_id": "a...@example.com ", "password": "xyz"}
>> I need to make it editable via the Django like below screen shot-
>>
>>
>> 
>>
>> I need your suggestion - what is the best way to achieve this?
>> I found a useful link for this purpose -
>> how-to-store-a-dictionary-on-a-django-model 
>> 
>>  but 
>> want to take your valuable guidance before proceeding so that I can 
>> implement with best practices.
>>
>> -- 
>> 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/eeaba88f-136a-4e03-9599-b564a596bdf8%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> Kind Regards, Yehor Smoliakov.
>
>
>
>

-- 
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/44e2b155-e62a-4724-9cb5-32437ca471d6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[no subject]

2018-06-27 Thread john speny
What is the best way of sending email message to another email
user...The one on the django.docs makes your account unsecure

-- 
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/CACxsAbDksgpqHJCi-x%3De976fSfj8uY8grw7fiz-s6urPTN%2BY4g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: better way to create a dictionary in Django model?

2018-06-27 Thread Bill Torcaso

You might find it helpful to look at the Wagtail CMS (wagtail.io).  It may 
not solve your problem, but Wagtail stores page-layout information in JSON 
format in a database column.  The JSON can be revised without modifying the 
database schema.

On Wednesday, June 27, 2018 at 8:18:09 AM UTC-4, prateek gupta wrote:
>
> Hi All,
>
> I am using Django 2.0.6 with Python 3.6 and MySql and created a model 
> which maps the db tables to django.
> In my database, I have a column 'config' of type json.
> This column stores the data in a dictionary format like below- 
> {"user_id": "a...@example.com ", "password": "xyz"}
> I need to make it editable via the Django like below screen shot-
>
>
> 
>
> I need your suggestion - what is the best way to achieve this?
> I found a useful link for this purpose -
> how-to-store-a-dictionary-on-a-django-model 
> 
>  but 
> want to take your valuable guidance before proceeding so that I can 
> implement with best practices.
>

-- 
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/95fcc428-ce8b-4de2-82f5-ff081f7099a0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Why do we need @cached_property behave like property when access from class?

2018-06-27 Thread 赖信桃
Hi, I'm reading the django's source code, and I am quite confused by
https://github.com/django/django/pull/812/files and
https://code.djangoproject.com/ticket/19872#no2

Why @cached_property need to return self when access from class?
https://docs.djangoproject.com/zh-hans/2.0/_modules/django/utils/functional/#cached_property

I see this PR for sure can make @cached_property behave like python's
@property, I have tested by myself here:
https://gist.github.com/laixintao/f1114d964c19679c973c2c3c3f1fa8ba#gistcomment-2631456
,
but still I can think out one useful situation.

Can somebody provide a condition that @cached_problem will cause problems
without return self when access from class?

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


Re: Why do we need @cached_property behave like property when access from class?

2018-06-27 Thread laixintao
> but still I can *NOT* think out one useful situation.

Sorry for the typo.

在 2018年6月27日星期三 UTC+8下午10:10:29,laixintao写道:
>
> Hi, I'm reading the django's source code, and I am quite confused by 
> https://github.com/django/django/pull/812/files and 
> https://code.djangoproject.com/ticket/19872#no2
>
> Why @cached_property need to return self when access from class? 
> https://docs.djangoproject.com/zh-hans/2.0/_modules/django/utils/functional/#cached_property
>
> I see this PR for sure can make @cached_property behave like python's 
> @property, I have tested by myself here: 
> https://gist.github.com/laixintao/f1114d964c19679c973c2c3c3f1fa8ba#gistcomment-2631456
>  , 
> but still I can think out one useful situation.
>
> Can somebody provide a condition that @cached_problem will cause problems 
> without return self when access from class?
>

-- 
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/d96fa435-1324-4d8d-bdb8-7e54b1f9dfa9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: better way to create a dictionary in Django model?

2018-06-27 Thread Mark Phillips
The way I work with json data in the admin is rather complicated. Here are
a the steps I use - check the django documentation and Google for details.

As an example, assume you have a table Documents with a JSON field called
metadata and other "normal" django fields. The metadata is a dictionary of
key - value pairs. Note: the "value" can be a string, list, dictionary,
integer, real, etc. It all depends on your needs and the field/widget you
define for your field.

1. Create a DocumentAdminForm(forms. ModelForm)
2. Override the __init__ method in the DocumentAdminForm to create all of
your JSON fields. I use the key as the name of the field. You will have
field definitions of the form
self.fields[key] = forms.CharField(). You can use any field type - DateField, BooleanField,
ModelChoiceField, ModelMultipleChoiceField, etc. For the last two fields,
your value will be a list in the JSON data. You can also use any of the
django or admin widgets for these fields - just add them to the field
definition.
3. To initialize the field with data from your JSON field, use
self.fields[key].initial = 
in the __init__ method.
4. In django > 1.8, be sure to have fields='__all__' in the Meta section of
the DocumentAdminForm
5. Override the clean method to validate the data you get back from the
form. There will be an entry in the self.cleaned_data dictionary for each
field in the form. You have to go through all the entries for your JSON
keys, validate whether the data is good or not, save them into a metadata
dictionary of the correct form for your JSON field, and remove that field
from the self.cleaned_data dictionary. At the end, the self.cleaned_data
should only have the fields that are defined in your model, and one
dictionary for your metadata JSON object. If one of the JSON fields has bad
data, then add a validation error to self.add_errors(key, validation_error)
- still remove this field info from the self.cleaned_data.

Create a DocumentAdmin(model.Admin) class.
1. set the form = DocumentAdminForm
2. Define a fieldset just for the fields in your model (not the JSON field)
3. Override get_form to flatten the fieldsets:
def get_form(self, request, obj=None, **kwargs):
kwargs['fields'] = flatten_fieldsets(self.fieldsets)
return super(DocumentAdmin, self).get_form(request, obj, **kwargs)

 4. Override get_fieldsets(self, request, obj=None) to add a fieldset
definition for your keys in the JSON object to the fieldsets object you
defined in step 2. Same keys used to define the fields in the form.

And that is about it! The admin page for your model will have a widget for
each of your keys in your JSON data. I can't post the code I use, but this
outline should give you enough pointers to look in the Django docs and get
some examples from Google.

Good luck!

Mark

On Wed, Jun 27, 2018 at 6:23 AM, prateek gupta  wrote:

> It has some limit- The configuration object can only be changed, there's
> no link for "add" (1)
>
> On Wednesday, June 27, 2018 at 6:41:41 PM UTC+5:30, Egor Smolyakov wrote:
>>
>> Better way it to use packages like this https://github.com/lazybird/dj
>> ango-solo
>>
>> On 27 June 2018 at 15:18, prateek gupta  wrote:
>>
>>> Hi All,
>>>
>>> I am using Django 2.0.6 with Python 3.6 and MySql and created a model
>>> which maps the db tables to django.
>>> In my database, I have a column 'config' of type json.
>>> This column stores the data in a dictionary format like below-
>>> {"user_id": "a...@example.com", "password": "xyz"}
>>> I need to make it editable via the Django like below screen shot-
>>>
>>>
>>> 
>>>
>>> I need your suggestion - what is the best way to achieve this?
>>> I found a useful link for this purpose -how-to-store-a-dictionary-on-
>>> a-django-model
>>> 
>>>  but
>>> want to take your valuable guidance before proceeding so that I can
>>> implement with best practices.
>>>
>>> --
>>> 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/eeaba88f-136a-4e03-9599-b564a596bdf8%40googlegroups.com
>>> 
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>> Kind Regards, Yehor Smoliakov.
>>
>>
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Djang

Re:

2018-06-27 Thread Mikhailo Keda
you can use external service, for example https://www.mailgun.com
https://simpleisbetterthancomplex.com/tutorial/2017/05/27/how-to-configure-mailgun-to-send-emails-in-a-django-app.html

середа, 27 червня 2018 р. 16:53:02 UTC+3 користувач john speny написав:
>
> What is the best way of sending email message to another email 
> user...The one on the django.docs makes your account unsecure 
>

-- 
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/31059896-e352-4251-a79a-5d0fe5ed1d4c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Deploy on Heroku

2018-06-27 Thread TimT Vogt
Also the instruction is in the screen to 

$ heroku config:set DISABLE_COLLECTSTATIC=1

Seems heroku want you to type this command



Verstuurd vanaf mijn iPhone

> Op 27 jun. 2018 om 14:29 heeft Fabio C. Barrionuevo da Luz  
> het volgende geschreven:
> 
> The error is explicitly here:
> 
> django.core.exceptions.ImproperlyConfigured: sets the REDIS_URL environment 
> variable
> 
> that is, you have not enabled the Redis plugin in Heroku.
> 
> As shown in the cookiecutter-django tutorial, it's just you, inside the 
> folder of your project, run:
> 
> heroku addons:create heroku-redis:hobby-dev
> 
> 
> 
> 
> 2018-06-27 9:03 GMT-03:00 Elias Coutinho :
>> Good Morning,
>> 
>> Following the deploy model of this tutorial, I was not successful.
>> 
>> Below the traceback of the terminal and then the heroku logs.
>> 
>> 
>> Where did I go wrong? I did not identify what the message meant.
>> 
>> 
>> 
>> 
>> 
>> 
>> -- 
>> 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/1c90951d-8a49-40be-b100-a584a19df446%40googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
> 
> 
> 
> -- 
> Fábio C. Barrionuevo da Luz
> Palmas - Tocantins - Brasil - América do Sul
> 
> http://pythonclub.com.br/
> 
> Blog colaborativo sobre Python e tecnologias Relacionadas, mantido totalmente 
> no https://github.com/pythonclub/pythonclub.github.io .
> 
> Todos são livres para publicar. É só fazer fork, escrever sua postagem e 
> mandar o pull-request. Leia mais sobre como publicar em README.md e 
> contributing.md.
> Regra básica de postagem:
> "Você" acha interessante? É útil para "você"? Pode ser utilizado com Python 
> ou é útil para quem usa Python? Está esperando o que? Publica logo, que estou 
> louco para ler...
> 
> -- 
> 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/CAPVjvMYsSTJ1P163JxHqY%3DT24zhGZEnR-hzZkznyeH8FVaGMLw%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/1A5CF36A-CEF9-4407-90B7-E88A4176F059%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Admin site not working properly using passenger on shared hosting. Need help setting it up properly

2018-06-27 Thread Pato
Ahmed, 

Did you manage to figure out what was the problem? I ran into the same 
problem. All POST requests  are throwing Page not found (404)
Request Method: POST


Let me know 

Thanks


On Friday, March 2, 2018 at 7:19:10 AM UTC-5, Tanvir Ahmed wrote:
>
> Hello, 
>
> I am fairly new to the web hosting world. I recently purchased a plan at 
> a2hosting. It's a shared hosting plan. After some problems with FastCGI, I 
> was told to use passenger to host django. I couldn't find much on this 
> topic and somehow managed to get the website working. However, soon I 
> realized that the post forms weren't working. More importantly, the admin 
> site wasn't working properly. I get to the admin site login but once I try 
> to login, I get a page not found error. 
>
> I have contacted the hosting provider and they seem to think that my 
> configuration with passenger is wrong. They were kind enough to offer to 
> change any server side settings if needed. So any idea what I am doing 
> wrong? Could you guys provide me the steps to get django working with 
> passenger? Or is it some server side settings fault?
>
> Please note that I decided to get rid of everything and start fresh. I 
> created a project by, first creating a virtualenv using CPanel's setup 
> python app. This also creates a passenger_wsgi.py and a .htaccess file. I 
> edited the passenger_wsgi.py to the following code: 
> from projectname.wsgi import application 
>
> After that I configured the settings where I made changes to the allowed 
> hosts and provided the static and media files and directories. Then I ran 
> collectstatics and made migrations and created superuser. Then, (keep in 
> mind I am using the project I just created and haven't changed anything or 
> added any apps) I went to, www.example.com/admin and the login appeared. 
> But, once I do try to login, I get a page not found error.
>
> The directory looks something like this: 
>
> root(/home/username)
> -virtualenv
> -website
> -passenger_wsgi.py
> -manage.py
> -public
> -tmp
> -project
> -__init__.py
> -settings.py
> -wsgi.py
> -urls.py
>
> Please note: there are other files but I included the ones I thought were 
> necessary.
>
> Thank you in advance and sorry for any inconveniences
>

-- 
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/19651712-8b5d-4a93-ad50-eab4daac474d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Invalid URLs passing validation by URLValidator

2018-06-27 Thread Tim Bell

Just picking up on a few points...

On Friday, 22 June 2018 21:51:01 UTC+10, Melvyn Sopacua wrote:
>
>   
>
However, officially, HTTP urls do not allow for username and password as 
> outlined in section 3.3:
>
>  
>
> An HTTP URL takes the form:
>
>
>   http://:/?
>
>
> where  and  are as described in Section 3.1. If :
>
> is omitted, the port defaults to 80.  No user name or password is
>
> allowed.
>
>
Except Django already decided they would accept 
them: https://code.djangoproject.com/ticket/20003

 

> So then, the parsing becomes:
>
> scheme = http
>
> host = foo
>
> path = /b...@example.com/
>

But "foo" is not a valid host, as it's not fully-qualified. (That's how the 
validator treats it, anyway.)

That said - Django still validates the ftp variant as being correct, so the 
> bug is still there and nice catch!
>
>
I've filed a bug (and created a pull 
request): https://code.djangoproject.com/ticket/29528

Cheers,

Tim Bell

-- 
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/ab468d8b-e389-42d6-a5fb-b72e6400c200%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Invalid URLs passing validation by URLValidator

2018-06-27 Thread Tim Bell


On Friday, 22 June 2018 20:53:54 UTC+10, Jason wrote:
>
> Interesting find.. the only time I've used that kind of URL convention is 
> by connecting to redis with the python redis library.  It also fits db url 
> connection strings too.
>
> What's the actual use case for the URL schema?
>

The use case is that I've extracted URLs like that from spam emails. (I 
work for an agency that regulates spam.) Clearly the software creating the 
emails had a bug that resulted in the invalid URLs, but nevertheless, I 
don't want the invalid URLs to break my system, so I check they're valid 
before further processing.

 

>
> You could also report this to the 
> https://groups.google.com/forum/#!forum/django-developers 
>  group 
> which is the core framework dev group, or report it as a bug on the django 
> bug tracker.
>

Reported as a bug (with a fix): https://code.djangoproject.com/ticket/29528

Cheers,

Tim Bell

-- 
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/3da47adf-e80f-4ddf-9335-c275b0724ed2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Queryset calculation and then filter/exclude/limit data rendered

2018-06-27 Thread rod termaat


I have a small checkbook application where I store transactions (expenses 
and income) amounts by date.  I render these to a template using python to 
add the cumulative balance prior to render.  This work fine for my little 
application, but not too sure how scalable it will be over time.


My goal is to have this displayed by month with the running balance.  I 
first researched custom pagination, but found nothing on date pagination by 
month and year.  I then started down the road of excluding data from the 
the queryset in the for loop which is easy in other languages, but this 
also seemed to be a no go.  My current thought is to exclude the data from 
the queryset in the for loop and move the data into a dictionary or list, 
or json.


Any advice for me?  Right now I need all objects from the Check model to 
get an accurate balance and then I need to filter that to limit the records 
by month.


Finally, I did tried to filter the check_list after the balance was added, 
but found out that does not work as the query goes back to the model and I 
loose the balance.


Here is my model


class Check(models.Model):

"""

Model representing a checkbook transaction.

"""

check_type = (('CR', 'credit'),('DR', 'debit'),('SV', 'savings'),('DT', 
'debt reduction'),)



dater = models.DateField(help_text=' .the date of the transaction')

type = models.CharField(max_length=2, choices=check_type, help_text=' 
.credit or debit')

category = models.ForeignKey('Category', on_delete=models.SET_NULL, 
null=True)

name = models.CharField(max_length=100, help_text=' .description')

amount = models.IntegerField(default=0, help_text=' .amount')

cleared = models.BooleanField(help_text=' .cleared with the bank?')

created = models.DateTimeField(auto_now_add=True)


Here is my function view


def checkbookList(request):

check_list = Check.objects.all()

#checks = Check.objects.all()

   

balance = 0

#for chk in checks:

for chk in check_list:

balance += chk.amount

chk.balance = balance


if chk.cleared:

chk.cleared = '\u221A'

else:

chk.cleared = '-'


return render(request, 'checkbook/checkbook.html', {'checks': 
check_list})

-- 
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/3db2052a-ba54-4f20-adca-ed42126c5b92%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Beginner

2018-06-27 Thread Harsh Rawat
I have learnt Django a little bit. I need help regarding the ticket 
https://code.djangoproject.com/ticket/28905 .What should I learn in Django 
to be able to contribute via this ticket.

-- 
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/1d490e7d-424f-421f-9278-2b326d95b397%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django's cache framework problem

2018-06-27 Thread 林挺滨
class Log(models.Model):
type = models.CharField(max_length=200, unique=True)
column = SortedManyToManyField(Column, blank=True)
min_column_cnt = models.IntegerField(blank=True, default=0,
help_text='0 equal NULL')

@cached_property
def column_list_name(self):
return [col.name for col in self.column.all()]

@cached_property
def column_len(self):
return len(self.column.all())

@cached_property
def get_all_column_checker(self):
column_ids = [c.id for c in self.column.all()]
return 
ColumnChecker.objects.select_related('column').filter(column_id__in=column_ids)


def get_log_attr(log_type):
global log_attr_dict, log_attr_last_update_ts
if (datetime.now() - log_attr_last_update_ts).total_seconds() <
update_log_attr_interval and \
log_type in log_attr_dict:
return log_attr_dict[log_type]
log_attr_dict[log_type] =
Log.objects.prefetch_related('column').get(type=log_type)
log_attr_last_update_ts = datetime.now()
return log_attr_dict[log_type]


Now I use module global var "log_attr_dict" to cache the Log instance,
@cached_property of the instance is work.

def get_log_attr(log_type):
log_attr = cache.get(log_type)
if not log_attr:
log_attr = Log.objects.prefetch_related('column').get(type=log_type)
cache.set(log_type, log_attr, update_log_attr_interval)
return log_attr


But if I use cache api to cache the Log instance, @cache_property of the
instance isn't work. (I use the local memory cache.)

赖信桃  于2018年6月27日周三 下午9:07写道:

> Show me your code snippet.
>
> 林挺滨 于2018年6月27日周三 下午8:44写道:
>
>> When I use cache framework api to cache a model instance,  @cached_property
>> of the instance doesn't work. Why?
>>
>> --
>> 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/5b27fa47-c712-460f-a421-1eb1d41c764e%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/CAMv51WQMrueCfWoBV3a0Djr7QhL3mqXcg_Ak5yNt75%3DP2Vy4WA%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/CAGdZMg8v2mp%3DOiO3coBFypGZ5O%2B_FLC_5cfnK94CRXax0OHRYw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django's cache framework problem

2018-06-27 Thread 赖信桃
Django's cached framework and @cached_property are two different things,
though both has "cached" it doesn't mean that they share memory

https://docs.djangoproject.com/zh-hans/2.0/topics/cache/
https://docs.djangoproject.com/zh-hans/2.0/ref/utils/#module-django.utils.functional

Read the docs.

林挺滨 于2018年6月28日周四 上午10:31写道:

> class Log(models.Model):
> type = models.CharField(max_length=200, unique=True)
> column = SortedManyToManyField(Column, blank=True)
> min_column_cnt = models.IntegerField(blank=True, default=0, help_text='0 
> equal NULL')
>
> @cached_property
> def column_list_name(self):
> return [col.name for col in self.column.all()]
>
> @cached_property
> def column_len(self):
> return len(self.column.all())
>
> @cached_property
> def get_all_column_checker(self):
> column_ids = [c.id for c in self.column.all()]
> return 
> ColumnChecker.objects.select_related('column').filter(column_id__in=column_ids)
>
>
> def get_log_attr(log_type):
> global log_attr_dict, log_attr_last_update_ts
> if (datetime.now() - log_attr_last_update_ts).total_seconds() < 
> update_log_attr_interval and \
> log_type in log_attr_dict:
> return log_attr_dict[log_type]
> log_attr_dict[log_type] = 
> Log.objects.prefetch_related('column').get(type=log_type)
> log_attr_last_update_ts = datetime.now()
> return log_attr_dict[log_type]
>
>
> Now I use module global var "log_attr_dict" to cache the Log instance,
> @cached_property of the instance is work.
>
> def get_log_attr(log_type):
> log_attr = cache.get(log_type)
> if not log_attr:
> log_attr = Log.objects.prefetch_related('column').get(type=log_type)
> cache.set(log_type, log_attr, update_log_attr_interval)
> return log_attr
>
>
> But if I use cache api to cache the Log instance, @cache_property of the
> instance isn't work. (I use the local memory cache.)
>
> 赖信桃  于2018年6月27日周三 下午9:07写道:
>
>> Show me your code snippet.
>>
>> 林挺滨 于2018年6月27日周三 下午8:44写道:
>>
>>> When I use cache framework api to cache a model instance,  @cached_property
>>> of the instance doesn't work. Why?
>>>
>>> --
>>> 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/5b27fa47-c712-460f-a421-1eb1d41c764e%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/CAMv51WQMrueCfWoBV3a0Djr7QhL3mqXcg_Ak5yNt75%3DP2Vy4WA%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/CAGdZMg8v2mp%3DOiO3coBFypGZ5O%2B_FLC_5cfnK94CRXax0OHRYw%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/CAMv51WTfA

Re: better way to create a dictionary in Django model?

2018-06-27 Thread prateek gupta
Thanks Mark for sharing every step! It helps a lot.

On Wednesday, June 27, 2018 at 7:57:25 PM UTC+5:30, mark wrote:
>
> The way I work with json data in the admin is rather complicated. Here are 
> a the steps I use - check the django documentation and Google for details.
>
> As an example, assume you have a table Documents with a JSON field called 
> metadata and other "normal" django fields. The metadata is a dictionary of 
> key - value pairs. Note: the "value" can be a string, list, dictionary, 
> integer, real, etc. It all depends on your needs and the field/widget you 
> define for your field.
>
> 1. Create a DocumentAdminForm(forms. ModelForm)
> 2. Override the __init__ method in the DocumentAdminForm to create all of 
> your JSON fields. I use the key as the name of the field. You will have 
> field definitions of the form
> self.fields[key] = forms.CharField( model>). You can use any field type - DateField, BooleanField, 
> ModelChoiceField, ModelMultipleChoiceField, etc. For the last two fields, 
> your value will be a list in the JSON data. You can also use any of the 
> django or admin widgets for these fields - just add them to the field 
> definition.
> 3. To initialize the field with data from your JSON field, use 
> self.fields[key].initial =  
> in the __init__ method.
> 4. In django > 1.8, be sure to have fields='__all__' in the Meta section 
> of the DocumentAdminForm
> 5. Override the clean method to validate the data you get back from the 
> form. There will be an entry in the self.cleaned_data dictionary for each 
> field in the form. You have to go through all the entries for your JSON 
> keys, validate whether the data is good or not, save them into a metadata 
> dictionary of the correct form for your JSON field, and remove that field 
> from the self.cleaned_data dictionary. At the end, the self.cleaned_data 
> should only have the fields that are defined in your model, and one 
> dictionary for your metadata JSON object. If one of the JSON fields has bad 
> data, then add a validation error to self.add_errors(key, validation_error) 
> - still remove this field info from the self.cleaned_data. 
>
> Create a DocumentAdmin(model.Admin) class. 
> 1. set the form = DocumentAdminForm
> 2. Define a fieldset just for the fields in your model (not the JSON field)
> 3. Override get_form to flatten the fieldsets:
> def get_form(self, request, obj=None, **kwargs):
> kwargs['fields'] = flatten_fieldsets(self.fieldsets)
> return super(DocumentAdmin, self).get_form(request, obj, **kwargs)
>
>  4. Override get_fieldsets(self, request, obj=None) to add a fieldset 
> definition for your keys in the JSON object to the fieldsets object you 
> defined in step 2. Same keys used to define the fields in the form.
>
> And that is about it! The admin page for your model will have a widget for 
> each of your keys in your JSON data. I can't post the code I use, but this 
> outline should give you enough pointers to look in the Django docs and get 
> some examples from Google. 
>
> Good luck!
>
> Mark
>
> On Wed, Jun 27, 2018 at 6:23 AM, prateek gupta  > wrote:
>
>> It has some limit- The configuration object can only be changed, there's 
>> no link for "add" (1)
>>
>> On Wednesday, June 27, 2018 at 6:41:41 PM UTC+5:30, Egor Smolyakov wrote:
>>>
>>> Better way it to use packages like this 
>>> https://github.com/lazybird/django-solo
>>>
>>> On 27 June 2018 at 15:18, prateek gupta  wrote:
>>>
 Hi All,

 I am using Django 2.0.6 with Python 3.6 and MySql and created a model 
 which maps the db tables to django.
 In my database, I have a column 'config' of type json.
 This column stores the data in a dictionary format like below- 
 {"user_id": "a...@example.com", "password": "xyz"}
 I need to make it editable via the Django like below screen shot-


 

 I need your suggestion - what is the best way to achieve this?
 I found a useful link for this purpose -
 how-to-store-a-dictionary-on-a-django-model 
 
  but 
 want to take your valuable guidance before proceeding so that I can 
 implement with best practices.

 -- 
 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/eeaba88f-136a-4e03-9599-b564a596bdf8%40googlegroups.com
  
 

Re: Django's cache framework problem

2018-06-27 Thread 林挺滨
https://docs.djangoproject.com/zh-hans/2.0/ref/utils/#module-django.utils.functional
 Say:
The cached result will persist as long as the instance does, so if the
instance is passed around and the function subsequently invoked, the cached
result will be returned.

https://docs.djangoproject.com/zh-hans/2.0/topics/cache/ Say:
 You can cache any Python object that can be pickled safely: strings,
dictionaries, lists of model objects, and so forth.

Then I use cache API to cache the model instance, "cached result" of the
instance should be cached together.

   - What is the problem?


赖信桃  于2018年6月28日周四 上午11:44写道:

> Django's cached framework and @cached_property are two different things,
> though both has "cached" it doesn't mean that they share memory
>
> https://docs.djangoproject.com/zh-hans/2.0/topics/cache/
>
> https://docs.djangoproject.com/zh-hans/2.0/ref/utils/#module-django.utils.functional
>
> Read the docs.
>
> 林挺滨 于2018年6月28日周四 上午10:31写道:
>
>> class Log(models.Model):
>> type = models.CharField(max_length=200, unique=True)
>> column = SortedManyToManyField(Column, blank=True)
>> min_column_cnt = models.IntegerField(blank=True, default=0, help_text='0 
>> equal NULL')
>>
>> @cached_property
>> def column_list_name(self):
>> return [col.name for col in self.column.all()]
>>
>> @cached_property
>> def column_len(self):
>> return len(self.column.all())
>>
>> @cached_property
>> def get_all_column_checker(self):
>> column_ids = [c.id for c in self.column.all()]
>> return 
>> ColumnChecker.objects.select_related('column').filter(column_id__in=column_ids)
>>
>>
>> def get_log_attr(log_type):
>> global log_attr_dict, log_attr_last_update_ts
>> if (datetime.now() - log_attr_last_update_ts).total_seconds() < 
>> update_log_attr_interval and \
>> log_type in log_attr_dict:
>> return log_attr_dict[log_type]
>> log_attr_dict[log_type] = 
>> Log.objects.prefetch_related('column').get(type=log_type)
>> log_attr_last_update_ts = datetime.now()
>> return log_attr_dict[log_type]
>>
>>
>> Now I use module global var "log_attr_dict" to cache the Log instance,
>> @cached_property of the instance is work.
>>
>> def get_log_attr(log_type):
>> log_attr = cache.get(log_type)
>> if not log_attr:
>> log_attr = Log.objects.prefetch_related('column').get(type=log_type)
>> cache.set(log_type, log_attr, update_log_attr_interval)
>> return log_attr
>>
>>
>> But if I use cache api to cache the Log instance, @cache_property of the
>> instance isn't work. (I use the local memory cache.)
>>
>> 赖信桃  于2018年6月27日周三 下午9:07写道:
>>
>>> Show me your code snippet.
>>>
>>> 林挺滨 于2018年6月27日周三 下午8:44写道:
>>>
 When I use cache framework api to cache a model instance,  @cached_property
 of the instance doesn't work. Why?

 --
 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/5b27fa47-c712-460f-a421-1eb1d41c764e%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/CAMv51WQMrueCfWoBV3a0Djr7QhL3mqXcg_Ak5yNt75%3DP2Vy4WA%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/CAGdZMg8v2mp%3DOiO3coBFy

Re: Django's cache framework problem

2018-06-27 Thread 赖信桃
One is cached framework , one is just a better "property". Use cache api if
you want to keep some instances.
On Thu, Jun 28, 2018 at 13:11 林挺滨  wrote:

>
> https://docs.djangoproject.com/zh-hans/2.0/ref/utils/#module-django.utils.functional
>  Say:
> The cached result will persist as long as the instance does, so if the
> instance is passed around and the function subsequently invoked, the cached
> result will be returned.
>
> https://docs.djangoproject.com/zh-hans/2.0/topics/cache/ Say:
>  You can cache any Python object that can be pickled safely: strings,
> dictionaries, lists of model objects, and so forth.
>
> Then I use cache API to cache the model instance, "cached result" of the
> instance should be cached together.
>
>- What is the problem?
>
>
> 赖信桃  于2018年6月28日周四 上午11:44写道:
>
>> Django's cached framework and @cached_property are two different things,
>> though both has "cached" it doesn't mean that they share memory
>>
>> https://docs.djangoproject.com/zh-hans/2.0/topics/cache/
>>
>> https://docs.djangoproject.com/zh-hans/2.0/ref/utils/#module-django.utils.functional
>>
>> Read the docs.
>>
>> 林挺滨 于2018年6月28日周四 上午10:31写道:
>>
>>> class Log(models.Model):
>>> type = models.CharField(max_length=200, unique=True)
>>> column = SortedManyToManyField(Column, blank=True)
>>> min_column_cnt = models.IntegerField(blank=True, default=0, 
>>> help_text='0 equal NULL')
>>>
>>> @cached_property
>>> def column_list_name(self):
>>> return [col.name for col in self.column.all()]
>>>
>>> @cached_property
>>> def column_len(self):
>>> return len(self.column.all())
>>>
>>> @cached_property
>>> def get_all_column_checker(self):
>>> column_ids = [c.id for c in self.column.all()]
>>> return 
>>> ColumnChecker.objects.select_related('column').filter(column_id__in=column_ids)
>>>
>>>
>>> def get_log_attr(log_type):
>>> global log_attr_dict, log_attr_last_update_ts
>>> if (datetime.now() - log_attr_last_update_ts).total_seconds() < 
>>> update_log_attr_interval and \
>>> log_type in log_attr_dict:
>>> return log_attr_dict[log_type]
>>> log_attr_dict[log_type] = 
>>> Log.objects.prefetch_related('column').get(type=log_type)
>>> log_attr_last_update_ts = datetime.now()
>>> return log_attr_dict[log_type]
>>>
>>>
>>> Now I use module global var "log_attr_dict" to cache the Log instance,
>>> @cached_property of the instance is work.
>>>
>>> def get_log_attr(log_type):
>>> log_attr = cache.get(log_type)
>>> if not log_attr:
>>> log_attr = Log.objects.prefetch_related('column').get(type=log_type)
>>> cache.set(log_type, log_attr, update_log_attr_interval)
>>> return log_attr
>>>
>>>
>>> But if I use cache api to cache the Log instance, @cache_property of the
>>> instance isn't work. (I use the local memory cache.)
>>>
>>> 赖信桃  于2018年6月27日周三 下午9:07写道:
>>>
 Show me your code snippet.

 林挺滨 于2018年6月27日周三 下午8:44写道:

> When I use cache framework api to cache a model instance,  
> @cached_property
> of the instance doesn't work. Why?
>
> --
> 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/5b27fa47-c712-460f-a421-1eb1d41c764e%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/CAMv51WQMrueCfWoBV3a0Djr7QhL3mqXcg_Ak5yNt75%3DP2Vy4WA%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 d

Re: Django's cache framework problem

2018-06-27 Thread 林挺滨
I use cache api to keep model instances, but "@cache_property" isn't work.
Now I use the module global var to keep model instances.

赖信桃  于2018年6月28日周四 下午1:29写道:

> One is cached framework , one is just a better "property". Use cache api
> if you want to keep some instances.
> On Thu, Jun 28, 2018 at 13:11 林挺滨  wrote:
>
>>
>> https://docs.djangoproject.com/zh-hans/2.0/ref/utils/#module-django.utils.functional
>>  Say:
>> The cached result will persist as long as the instance does, so if the
>> instance is passed around and the function subsequently invoked, the cached
>> result will be returned.
>>
>> https://docs.djangoproject.com/zh-hans/2.0/topics/cache/ Say:
>>  You can cache any Python object that can be pickled safely: strings,
>> dictionaries, lists of model objects, and so forth.
>>
>> Then I use cache API to cache the model instance, "cached result" of the
>> instance should be cached together.
>>
>>- What is the problem?
>>
>>
>> 赖信桃  于2018年6月28日周四 上午11:44写道:
>>
>>> Django's cached framework and @cached_property are two different things,
>>> though both has "cached" it doesn't mean that they share memory
>>>
>>> https://docs.djangoproject.com/zh-hans/2.0/topics/cache/
>>>
>>> https://docs.djangoproject.com/zh-hans/2.0/ref/utils/#module-django.utils.functional
>>>
>>> Read the docs.
>>>
>>> 林挺滨 于2018年6月28日周四 上午10:31写道:
>>>
 class Log(models.Model):
 type = models.CharField(max_length=200, unique=True)
 column = SortedManyToManyField(Column, blank=True)
 min_column_cnt = models.IntegerField(blank=True, default=0, 
 help_text='0 equal NULL')

 @cached_property
 def column_list_name(self):
 return [col.name for col in self.column.all()]

 @cached_property
 def column_len(self):
 return len(self.column.all())

 @cached_property
 def get_all_column_checker(self):
 column_ids = [c.id for c in self.column.all()]
 return 
 ColumnChecker.objects.select_related('column').filter(column_id__in=column_ids)


 def get_log_attr(log_type):
 global log_attr_dict, log_attr_last_update_ts
 if (datetime.now() - log_attr_last_update_ts).total_seconds() < 
 update_log_attr_interval and \
 log_type in log_attr_dict:
 return log_attr_dict[log_type]
 log_attr_dict[log_type] = 
 Log.objects.prefetch_related('column').get(type=log_type)
 log_attr_last_update_ts = datetime.now()
 return log_attr_dict[log_type]


 Now I use module global var "log_attr_dict" to cache the Log instance,
 @cached_property of the instance is work.

 def get_log_attr(log_type):
 log_attr = cache.get(log_type)
 if not log_attr:
 log_attr = 
 Log.objects.prefetch_related('column').get(type=log_type)
 cache.set(log_type, log_attr, update_log_attr_interval)
 return log_attr


 But if I use cache api to cache the Log instance, @cache_property of
 the instance isn't work. (I use the local memory cache.)

 赖信桃  于2018年6月27日周三 下午9:07写道:

> Show me your code snippet.
>
> 林挺滨 于2018年6月27日周三 下午8:44写道:
>
>> When I use cache framework api to cache a model instance,  
>> @cached_property
>> of the instance doesn't work. Why?
>>
>> --
>> 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/5b27fa47-c712-460f-a421-1eb1d41c764e%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/CAMv51WQMrueCfWoBV3a0Djr7QhL3mqXcg_Ak5yNt75%3DP2Vy4WA%40mail.gmail.com
> 
> .


> For more options, visit https://groups.g

Re: Beginner

2018-06-27 Thread 'Anthony Flury' via Django users

On 27/06/18 21:23, Harsh Rawat wrote:
I have learnt Django a little bit. I need help regarding the ticket 
https://code.djangoproject.com/ticket/28905 .What should I learn in 
Django to be able to contribute via this ticket.


It looks like this doesn't actually require any knowledge of Django 
particularly;  this feature is actually a feature of pip and Python 
setuptools.


What you need to do is identify a set of packages that are often 
installed with Django - and then identify a useful name for them.


As commented on the fault, you should probably agree any new set of 
packages on the developer mailing list, and also make sure that you 
clearly document which package sets are now supported.



--
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/1d490e7d-424f-421f-9278-2b326d95b397%40googlegroups.com 
.

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



--
--
Anthony Flury
email : *anthony.fl...@btinternet.com*
Twitter : *@TonyFlury *

--
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/bc94a651-1c5c-419d-8202-458ba9eb50b2%40btinternet.com.
For more options, visit https://groups.google.com/d/optout.