0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Python対話モード風にDjangoのモジュールを扱う

Posted at

###Djangoのsettingsが効いてる状態で対話式にAPIとかの動作確認をしたい

python manage.py shell

対話モードになります

Python 3.6.8 (tags/v3.6.8:3c6b436a57, Dec 24 2018, 00:16:47) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>>

Djangoのモデルや、ライブラリー等が、ソースに書く感覚で対話式に扱えます

>>> from links.models import Link
>>> from django.db.models import Q

>>> filter = (
... Q(url__icontains="code") | Q(description__icontains="code"))
>>> article = Link.objects.filter(filter)
>>> for e in article.all():
...     print(e.description)
code writing keep me sane
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?