These are chat archives for django/django

13th
Feb 2019
Miracle Ayodele
@iammiracle
Feb 13 06:23
Hi guys i need help with django JSONField
[{"url": "https://www.financialjuice.com/nasdaq/PIH", "date": "2019-02-12 12:58:57", "title": "PIH Health Offers Medicare Benefit Presentations, Forums During Medicare Enrollment Season", "source": "Benzinga", "category": "PIH", "full_name": "1347 Property Insurance Holdings, Inc."}, {"url": "https://www.financialjuice.com/nasdaq/PIH", "date": "2019-02-12 12:58:57", "title": "PIH Health Receives National Recognition from Healthgrades®", "source": "Benzinga", "category": "PIH", "full_name": "1347 Property Insurance Holdings, Inc."}, {"url": "https://www.financialjuice.com/nasdaq/PIH", "date": "2019-02-12 12:58:58", "title": "PIH Health Primary Care Physicians Offer an Array of Services to Better Patient Health", "source": "Benzinga", "category": "PIH", "full_name": "1347 Property Insurance Holdings, Inc."}, {"url": "https://www.financialjuice.com/nasdaq/PIH", "date": "2019-02-12 12:58:58", "title": "PIH Health Offers Tips on Selecting Health Plan Options", "source": "Benzinga", "category": "PIH", "full_name": "1347 Property Insurance Holdings, Inc."}, {"url": "https://www.financialjuice.com/nasdaq/PIH", "date": "2019-02-12 12:58:59", "title": "PIH Health Opens Urgent Care Centers to Bring the Right Level of Care to the Community", "source": "Benzinga", "category": "PIH", "full_name": "1347 Property Insurance Holdings, Inc."}, {"url": "https://www.financialjuice.com/nasdaq/PIH", "date": "2019-02-12 12:58:59", "title": "BRIEF-1347 Property Insurance Holdings Inc provides update on strategic review process and announces changes to the board of directors", "source": "Reuters", "category": "PIH", "full_name": "1347 Property Insurance Holdings, Inc."}]
Miracle Ayodele
@iammiracle
Feb 13 06:30
i tried using NewsModel.objects.filter( metadata__icontains=[{'full_name': '1347 Property Insurance Holdings, Inc.' }]
i got the whole dictionary, if i search using some part like "1347 Property Insurance ", i get nothing
Miracle Ayodele
@iammiracle
Feb 13 06:36
also, how can i do pagination on JSONField
slimack
@theslimack_twitter
Feb 13 12:22
Hello
prog omar ahmed
@omarKady
Feb 13 15:33
hi guys i created my project with sqllite how can i transform into postgresql
Peter Bittner
@bittner
Feb 13 15:35

A question on Django settings:

Is there someone proposing to use specific settings for CI builds, pipelines, whatever? I see this at another client of ours, and I'm starting to wonder who gave birth to this ... :poop:

Peter Bittner
@bittner
Feb 13 16:25
Is someone else here using specific Django settings just for CI builds and pipelines?
matrixbot
@matrixbot
Feb 13 16:45

@exilkoelner:matrix.org > <@gitter_omarkady:matrix.org> hi guys i created my project with sqllite how can i transform into postgresql

Through django-admin dumpdata you geht JSON.

Then change

DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': 'mydatabase', } }

to

DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', 'NAME': 'mydatabase', 'USER': 'mydatabaseuser', 'PASSWORD': 'mypassword', 'HOST': '127.0.0.1', 'PORT': '5432', } }

Then use

django-admin loaddata

More Info in the docs.

prog omar ahmed
@omarKady
Feb 13 16:47
@matrixbot ok i will try it now
prog omar ahmed
@omarKady
Feb 13 17:19
@matrixbot ok i have an error
i created my project and then i changed database settings but i have an error because of postgresql psycopg2
Peter Bittner
@bittner
Feb 13 17:20

@omarKady The true (but less helpful) answer is: You shouldn't "transform" your data from SQLite to PostgreSQL.

  • The database schema should be created by your migrations (ideally, there's nothing to do here for you except changing the DATABASES setting)
  • The data, if you have initial data, you should create via the ORM (not fixtures), this is probably the only stable way to get your data into virtually any database
  • All the other data you should write Python code for (e.g. a management command) to move it from one database to the other (this will obviously use the ORM)

Seriously: Forget about exporting the data as SQL, trying to clean it up and importing it again. DON'T DO IT. You're not the first to try this.

prog omar ahmed
@omarKady
Feb 13 17:22
@bittner ok but can i make a big projects by sqlite ?
Peter Bittner
@bittner
Feb 13 17:22
No. Of course not. (But that's a different question, isn't it?)
I said, don't export SQL. Use Python code to move your data from one database to another, understand?
prog omar ahmed
@omarKady
Feb 13 17:25
@bittner now i created my project and i want to use postgresql
after migrations i have error because of psycopg2
Peter Bittner
@bittner
Feb 13 17:26
Post the exception and the steps you performed. (Otherwise it would all be guessing from everyone here.)
prog omar ahmed
@omarKady
Feb 13 17:29
@bittner ok

$ cd my-django
$ . env/bin/activate
(env) $ django-admin startproject arenanews
(env) $ cd arenanews
(env) $ python manage.py runserver
Performing system checks...

System check identified no issues (0 silenced).

You have 15 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.

February 13, 2019 - 17:29:11
Django version 2.1.4, using settings 'arenanews.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[13/Feb/2019 17:29:32] "GET / HTTP/1.1" 200 16348

Peter Bittner
@bittner
Feb 13 17:53
You need to run python manage.py migrate
prog omar ahmed
@omarKady
Feb 13 17:53
i did
Peter Bittner
@bittner
Feb 13 17:54

So, why does Django complain? What do you think?

Run 'python manage.py migrate' to apply them.

prog omar ahmed
@omarKady
Feb 13 17:55
now i want to connect to other database backends, such as postgresql
Peter Bittner
@bittner
Feb 13 18:29
When you start your project from scratch this is easy: Simply change the DATABASES setting as by the Django documentation.
Miracle Ayodele
@iammiracle
Feb 13 19:07
Hi guys, what is the format of a JSONField is it [{'a' :'b' }] or {'a' :'b' }
Peter Bittner
@bittner
Feb 13 23:02
@iammiracle A dictionary, according to the Django docs.
blstdmi
@blstdmi
Feb 13 23:03
connection.execute("select T1.* from ( values (10,'Акулина') , (20,'Бронислав') , (30,'Богдан') , (40,'Борислав')) as T1").fetchall()
how to select column 1 or set name to column??
T1. column?
blstdmi
@blstdmi
Feb 13 23:11
ok it easy T1.column2