An open API service indexing awesome lists of open source software.

https://github.com/queeniecplusplus/backend_script3_blogapp_models

Django migrates with SQLite3 using shell and admin UI platform
https://github.com/queeniecplusplus/backend_script3_blogapp_models

django python shell sqlite3

Last synced: 3 months ago
JSON representation

Django migrates with SQLite3 using shell and admin UI platform

Awesome Lists containing this project

README

          

# Backend_Script3_Blogapp_Models
Django migrates with SQLite3 using shell and admin UI platform

![](https://raw.githubusercontent.com/QueenieCplusplus/Backend_Script3_-logapp_Models/main/18%20post2.png)

prepare virtual env =>

~$ which python3
show >> path_to_be_copied

~$ virtualenv -p path_to_be_copied vir_name

~$ source vir_name/bin/activate

// to leave the virtualenv
(vir_name) ~$ deactivate

(vir_name) ~$ pip list

(vir_name) ~$ pip3 install django

(vir_name) ~$ mkdir proj_name


(vir_name) ~$cd proj_name

(vir_name) proj_name$ django-admin startproject site_name_top_level

(vir_name) proj_name$ cd site_name_top_level

(vir_name) site_name$ ls

site_name_sub_level/settings.py + urls.py

manage.py

(sqlite3 waits to be created)

(blog app waits to be created)/models.py + views.py + admin.py + migration + apps.py

top level site cmd => (all manage.py cmd shall run under the top level site dir instead of sub level)

python manage.py runserver

python manage.py makemigrations

python manage.py migrate


create a blog =>


python manage.py startapp kblog


create super user =>


python3 manage.py createsuperuser

Username (leave blank to use 'katesandroid'): xxxxx
Email address: xxx@gmail.com
Password:
Password (again):
Superuser created successfully.
(k0219) KatesAndroiddeMacBook-Pro:site0219 katesandroid$ python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...



db operations =>

python manage.py shell



>>> from kblog.models import Post
>>> Post.objects.all()
>>>
>>>



>>> Post.objects.create(author=user, title='Sample title', text='Test')
>>>
Traceback (most recent call last):
File "", line 1, in
NameError: name 'user' is not defined
>>> Post.objects.create(author='kate chen', title='Sample title', text='Test')
ValueError: Cannot assign "'kate chen'": "Post.author" must be a "User" instance.


>>> from django.contrib.auth.models import User
>>> User.objects.all()



>>> user = User.objects.get(username='Poupou Chen')
Traceback (most recent call last):
File "", line 1, in
File "/Users/katesandroid/k0219/lib/python3.8/site-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/Users/katesandroid/k0219/lib/python3.8/site-packages/django/db/models/query.py", line 429, in get
raise self.model.DoesNotExist(
django.contrib.auth.models.User.DoesNotExist: User matching query does not exist.


>>> from django.contrib.auth.models import User
>>> User.objects.all()



>>> from django.contrib.auth.models import User
>>> user = User.objects.create_user('Poupou', 'poupou@pattyappier.com', '0123456789')
>>> user.save()
>>>

>>> from django.contrib.auth.models import User
>>> User.objects.all()
]>


>>> user = User.objects.get(username='Poupou')
>>> Post.objects.create(author = user, title = 'Cats Lovely Home', text = 'Test')



>>> Post.objects.all()
]>


>>> post = Post.objects.get(id=1)
>>> post.publish()
>>>
>>> Post.objects.filter(published_date__isnull=False)
]>
>>> exit()

deprecated cmd => https://stackoverflow.com/questions/17392015/error-while-creating-a-model-in-django

create superuser => https://developer.mozilla.org/zh-TW/docs/Learn/Server-side/Django/Admin_site

blog app & models init => https://carolhsu.gitbooks.io/django-girls-tutorial-traditional-chiness/content/django_start_project/README.html

models tip => https://www.itread01.com/content/1545016715.html

create user => https://docs.djangoproject.com/en/3.1/topics/auth/default/