feat: ✨ user
This commit is contained in:
parent
5dd685e882
commit
ef4ca9ab6a
17 changed files with 244 additions and 85 deletions
202
.gitignore
vendored
202
.gitignore
vendored
|
@ -1,77 +1,159 @@
|
||||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
|
# Byte-compiled / optimized / DLL files
|
||||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
__pycache__/
|
||||||
|
*.py[cod]
|
||||||
|
*$py.class
|
||||||
|
|
||||||
# User-specific stuff
|
|
||||||
.idea/**/workspace.xml
|
|
||||||
.idea/**/tasks.xml
|
|
||||||
.idea/**/usage.statistics.xml
|
|
||||||
.idea/**/dictionaries
|
|
||||||
.idea/**/shelf
|
|
||||||
|
|
||||||
# AWS User-specific
|
# C extensions
|
||||||
.idea/**/aws.xml
|
*.so
|
||||||
|
|
||||||
# Generated files
|
# Distribution / packaging
|
||||||
.idea/**/contentModel.xml
|
.Python
|
||||||
|
build/
|
||||||
|
develop-eggs/
|
||||||
|
dist/
|
||||||
|
downloads/
|
||||||
|
eggs/
|
||||||
|
.eggs/
|
||||||
|
lib/
|
||||||
|
lib64/
|
||||||
|
parts/
|
||||||
|
sdist/
|
||||||
|
var/
|
||||||
|
wheels/
|
||||||
|
share/python-wheels/
|
||||||
|
*.egg-info/
|
||||||
|
.installed.cfg
|
||||||
|
*.egg
|
||||||
|
MANIFEST
|
||||||
|
|
||||||
# Sensitive or high-churn files
|
# PyInstaller
|
||||||
.idea/**/dataSources/
|
# Usually these files are written by a python script from a template
|
||||||
.idea/**/dataSources.ids
|
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||||
.idea/**/dataSources.local.xml
|
*.manifest
|
||||||
.idea/**/sqlDataSources.xml
|
*.spec
|
||||||
.idea/**/dynamic.xml
|
|
||||||
.idea/**/uiDesigner.xml
|
|
||||||
.idea/**/dbnavigator.xml
|
|
||||||
|
|
||||||
# Gradle
|
# Installer logs
|
||||||
.idea/**/gradle.xml
|
pip-log.txt
|
||||||
.idea/**/libraries
|
pip-delete-this-directory.txt
|
||||||
|
|
||||||
# Gradle and Maven with auto-import
|
# Unit test / coverage reports
|
||||||
# When using Gradle or Maven with auto-import, you should exclude module files,
|
htmlcov/
|
||||||
# since they will be recreated, and may cause churn. Uncomment if using
|
.tox/
|
||||||
# auto-import.
|
.nox/
|
||||||
# .idea/artifacts
|
.coverage
|
||||||
# .idea/compiler.xml
|
.coverage.*
|
||||||
# .idea/jarRepositories.xml
|
.cache
|
||||||
# .idea/modules.xml
|
nosetests.xml
|
||||||
# .idea/*.iml
|
coverage.xml
|
||||||
# .idea/modules
|
*.cover
|
||||||
# *.iml
|
*.py,cover
|
||||||
# *.ipr
|
.hypothesis/
|
||||||
|
.pytest_cache/
|
||||||
|
cover/
|
||||||
|
|
||||||
# CMake
|
# Translations
|
||||||
cmake-build-*/
|
*.mo
|
||||||
|
*.pot
|
||||||
|
|
||||||
# Mongo Explorer plugin
|
# Django stuff:
|
||||||
.idea/**/mongoSettings.xml
|
*.log
|
||||||
|
local_settings.py
|
||||||
|
db.sqlite3
|
||||||
|
db.sqlite3-journal
|
||||||
|
|
||||||
# File-based project format
|
# Flask stuff:
|
||||||
*.iws
|
instance/
|
||||||
|
.webassets-cache
|
||||||
|
|
||||||
# IntelliJ
|
# Scrapy stuff:
|
||||||
out/
|
.scrapy
|
||||||
|
|
||||||
# mpeltonen/sbt-idea plugin
|
# Sphinx documentation
|
||||||
.idea_modules/
|
docs/_build/
|
||||||
|
|
||||||
# JIRA plugin
|
# PyBuilder
|
||||||
atlassian-ide-plugin.xml
|
.pybuilder/
|
||||||
|
target/
|
||||||
|
|
||||||
# Cursive Clojure plugin
|
# Jupyter Notebook
|
||||||
.idea/replstate.xml
|
.ipynb_checkpoints
|
||||||
|
|
||||||
# SonarLint plugin
|
# IPython
|
||||||
.idea/sonarlint/
|
profile_default/
|
||||||
|
ipython_config.py
|
||||||
|
|
||||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
# pyenv
|
||||||
com_crashlytics_export_strings.xml
|
# For a library or package, you might want to ignore these files since the code is
|
||||||
crashlytics.properties
|
# intended to run in multiple environments; otherwise, check them in:
|
||||||
crashlytics-build.properties
|
# .python-version
|
||||||
fabric.properties
|
|
||||||
|
|
||||||
# Editor-based Rest Client
|
# pipenv
|
||||||
.idea/httpRequests
|
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
||||||
|
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
||||||
|
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
||||||
|
# install all needed dependencies.
|
||||||
|
#Pipfile.lock
|
||||||
|
|
||||||
# Android studio 3.1+ serialized cache file
|
# poetry
|
||||||
.idea/caches/build_file_checksums.ser
|
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
||||||
|
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
||||||
|
# commonly ignored for libraries.
|
||||||
|
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
||||||
|
#poetry.lock
|
||||||
|
|
||||||
|
# pdm
|
||||||
|
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
||||||
|
#pdm.lock
|
||||||
|
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
||||||
|
# in version control.
|
||||||
|
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
|
||||||
|
.pdm.toml
|
||||||
|
.pdm-python
|
||||||
|
.pdm-build/
|
||||||
|
|
||||||
|
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
||||||
|
__pypackages__/
|
||||||
|
|
||||||
|
# Celery stuff
|
||||||
|
celerybeat-schedule
|
||||||
|
celerybeat.pid
|
||||||
|
|
||||||
|
# SageMath parsed files
|
||||||
|
*.sage.py
|
||||||
|
|
||||||
|
# Environments
|
||||||
|
.env
|
||||||
|
.venv
|
||||||
|
env/
|
||||||
|
venv/
|
||||||
|
ENV/
|
||||||
|
env.bak/
|
||||||
|
venv.bak/
|
||||||
|
|
||||||
|
# Spyder project settings
|
||||||
|
.spyderproject
|
||||||
|
.spyproject
|
||||||
|
|
||||||
|
# Rope project settings
|
||||||
|
.ropeproject
|
||||||
|
|
||||||
|
# mkdocs documentation
|
||||||
|
/site
|
||||||
|
|
||||||
|
# mypy
|
||||||
|
.mypy_cache/
|
||||||
|
.dmypy.json
|
||||||
|
dmypy.json
|
||||||
|
|
||||||
|
# Pyre type checker
|
||||||
|
.pyre/
|
||||||
|
|
||||||
|
# pytype static type analyzer
|
||||||
|
.pytype/
|
||||||
|
|
||||||
|
# Cython debug symbols
|
||||||
|
cython_debug/
|
||||||
|
|
||||||
|
.idea/
|
||||||
|
.vscode/
|
34
.idea/workspace.xml
generated
34
.idea/workspace.xml
generated
|
@ -5,7 +5,12 @@
|
||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="b4bf3f98-d5b7-4d99-9ccf-5a322ed50222" name="Changes" comment="">
|
<list default="true" id="b4bf3f98-d5b7-4d99-9ccf-5a322ed50222" name="Changes" comment="">
|
||||||
|
<change beforePath="$PROJECT_DIR$/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/.vscode/settings.json" beforeDir="false" afterPath="$PROJECT_DIR$/.vscode/settings.json" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/db.sqlite3" beforeDir="false" afterPath="$PROJECT_DIR$/db.sqlite3" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/tJango/settings.py" beforeDir="false" afterPath="$PROJECT_DIR$/tJango/settings.py" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/tJango/urls.py" beforeDir="false" afterPath="$PROJECT_DIR$/tJango/urls.py" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
|
@ -36,21 +41,21 @@
|
||||||
<option name="hideEmptyMiddlePackages" value="true" />
|
<option name="hideEmptyMiddlePackages" value="true" />
|
||||||
<option name="showLibraryContents" value="true" />
|
<option name="showLibraryContents" value="true" />
|
||||||
</component>
|
</component>
|
||||||
<component name="PropertiesComponent"><![CDATA[{
|
<component name="PropertiesComponent">{
|
||||||
"keyToString": {
|
"keyToString": {
|
||||||
"ASKED_ADD_EXTERNAL_FILES": "true",
|
"ASKED_ADD_EXTERNAL_FILES": "true",
|
||||||
"RunOnceActivity.OpenDjangoStructureViewOnStart": "true",
|
"RunOnceActivity.OpenDjangoStructureViewOnStart": "true",
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
"git-widget-placeholder": "main",
|
"git-widget-placeholder": "main",
|
||||||
"node.js.detected.package.eslint": "true",
|
"node.js.detected.package.eslint": "true",
|
||||||
"node.js.detected.package.tslint": "true",
|
"node.js.detected.package.tslint": "true",
|
||||||
"node.js.selected.package.eslint": "(autodetect)",
|
"node.js.selected.package.eslint": "(autodetect)",
|
||||||
"node.js.selected.package.tslint": "(autodetect)",
|
"node.js.selected.package.tslint": "(autodetect)",
|
||||||
"nodejs_package_manager_path": "npm",
|
"nodejs_package_manager_path": "npm",
|
||||||
"settings.editor.selected.configurable": "com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable",
|
"settings.editor.selected.configurable": "com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable",
|
||||||
"vue.rearranger.settings.migration": "true"
|
"vue.rearranger.settings.migration": "true"
|
||||||
}
|
}
|
||||||
}]]></component>
|
}</component>
|
||||||
<component name="RunManager">
|
<component name="RunManager">
|
||||||
<configuration name="tJango" type="Python.DjangoServer" factoryName="Django server">
|
<configuration name="tJango" type="Python.DjangoServer" factoryName="Django server">
|
||||||
<module name="tJango" />
|
<module name="tJango" />
|
||||||
|
@ -95,6 +100,7 @@
|
||||||
<updated>1719511805110</updated>
|
<updated>1719511805110</updated>
|
||||||
<workItem from="1719511812328" duration="309000" />
|
<workItem from="1719511812328" duration="309000" />
|
||||||
<workItem from="1719512143097" duration="830000" />
|
<workItem from="1719512143097" duration="830000" />
|
||||||
|
<workItem from="1719617813873" duration="422000" />
|
||||||
</task>
|
</task>
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
|
|
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
|
@ -1,4 +1,7 @@
|
||||||
{
|
{
|
||||||
|
"python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python",
|
||||||
|
"python.analysis.indexing": true,
|
||||||
|
"python.analysis.packageIndexDepths":[["rest_framework", 5, true]],
|
||||||
"cSpell.words": [
|
"cSpell.words": [
|
||||||
"viewsets"
|
"viewsets"
|
||||||
]
|
]
|
||||||
|
|
BIN
db.sqlite3
BIN
db.sqlite3
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -38,6 +38,8 @@ INSTALLED_APPS = [
|
||||||
'django.contrib.messages',
|
'django.contrib.messages',
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
'rest_framework',
|
'rest_framework',
|
||||||
|
'hello',
|
||||||
|
'user',
|
||||||
]
|
]
|
||||||
|
|
||||||
REST_FRAMEWORK = {
|
REST_FRAMEWORK = {
|
||||||
|
|
|
@ -17,23 +17,17 @@ Including another URLconf
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import path, include
|
from django.urls import path, include
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from rest_framework import routers, serializers, viewsets
|
from rest_framework.routers import DefaultRouter
|
||||||
|
from user.views import UserViewSet
|
||||||
|
|
||||||
class UserSerializer(serializers.HyperlinkedModelSerializer):
|
|
||||||
class Meta:
|
|
||||||
model = User
|
|
||||||
fields = ['url', 'username', 'email', 'is_staff']
|
|
||||||
|
|
||||||
class UserViewSet(viewsets.ModelViewSet):
|
router = DefaultRouter()
|
||||||
queryset = User.objects.all()
|
|
||||||
serializer_class = UserSerializer
|
|
||||||
|
|
||||||
router = routers.DefaultRouter()
|
|
||||||
router.register(r'users', UserViewSet)
|
router.register(r'users', UserViewSet)
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('api-auth/', include('rest_framework.urls')),
|
path('api-auth/', include('rest_framework.urls')),
|
||||||
path('hello', include("hello.urls")),
|
path('hello/', include("hello.urls")),
|
||||||
path('', include(router.urls)),
|
path('', include(router.urls)),
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
|
path('user/', include((router.urls, 'user'), namespace='user'))
|
||||||
]
|
]
|
||||||
|
|
0
user/__init__.py
Normal file
0
user/__init__.py
Normal file
5
user/admin.py
Normal file
5
user/admin.py
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
from django.contrib import admin
|
||||||
|
from .models import User
|
||||||
|
# Register your models here.
|
||||||
|
|
||||||
|
admin.site.register(User)
|
6
user/apps.py
Normal file
6
user/apps.py
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class UserConfig(AppConfig):
|
||||||
|
default_auto_field = 'django.db.models.BigAutoField'
|
||||||
|
name = 'user'
|
22
user/migrations/0001_initial.py
Normal file
22
user/migrations/0001_initial.py
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
# Generated by Django 5.0.6 on 2024-06-28 00:23
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='User',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('username', models.CharField(max_length=15)),
|
||||||
|
('date_created', models.DateTimeField(auto_now_add=True)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
0
user/migrations/__init__.py
Normal file
0
user/migrations/__init__.py
Normal file
12
user/models.py
Normal file
12
user/models.py
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
from django.db import models
|
||||||
|
|
||||||
|
|
||||||
|
# Create your models here.
|
||||||
|
|
||||||
|
class User(models.Model):
|
||||||
|
username = models.CharField(max_length=15, unique=True)
|
||||||
|
date_created = models.DateTimeField(auto_now_add=True)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.username
|
||||||
|
|
8
user/serializers.py
Normal file
8
user/serializers.py
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
from rest_framework import serializers
|
||||||
|
from .models import User
|
||||||
|
|
||||||
|
class UserSerializer(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = User
|
||||||
|
fields = ['username', 'date_created']
|
||||||
|
read_only_fields = ['date_created']
|
3
user/tests.py
Normal file
3
user/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
16
user/views.py
Normal file
16
user/views.py
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
from django.shortcuts import render
|
||||||
|
from rest_framework import viewsets
|
||||||
|
from rest_framework.decorators import action
|
||||||
|
from .models import User
|
||||||
|
from .serializers import UserSerializer
|
||||||
|
|
||||||
|
|
||||||
|
# Create your views here.
|
||||||
|
|
||||||
|
class UserViewSet(viewsets.ModelViewSet):
|
||||||
|
queryset = User.objects.all()
|
||||||
|
serializer_class = UserSerializer
|
||||||
|
|
||||||
|
@action(detail=True, methods=['get'])
|
||||||
|
def print_this(self, request, pk=None):
|
||||||
|
print(self.get_object())
|
Loading…
Add table
Add a link
Reference in a new issue