feat: user

This commit is contained in:
Tahinli 2024-06-29 03:03:21 +03:00
parent 5dd685e882
commit ef4ca9ab6a
17 changed files with 244 additions and 85 deletions

202
.gitignore vendored
View file

@ -1,77 +1,159 @@
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# Byte-compiled / optimized / DLL files
__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
.idea/**/aws.xml
# C extensions
*.so
# Generated files
.idea/**/contentModel.xml
# Distribution / packaging
.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
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
# CMake
cmake-build-*/
# Translations
*.mo
*.pot
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# File-based project format
*.iws
# Flask stuff:
instance/
.webassets-cache
# IntelliJ
out/
# Scrapy stuff:
.scrapy
# mpeltonen/sbt-idea plugin
.idea_modules/
# Sphinx documentation
docs/_build/
# JIRA plugin
atlassian-ide-plugin.xml
# PyBuilder
.pybuilder/
target/
# Cursive Clojure plugin
.idea/replstate.xml
# Jupyter Notebook
.ipynb_checkpoints
# SonarLint plugin
.idea/sonarlint/
# IPython
profile_default/
ipython_config.py
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
# Editor-based Rest Client
.idea/httpRequests
# pipenv
# 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
.idea/caches/build_file_checksums.ser
# poetry
# 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
View file

@ -5,7 +5,12 @@
</component>
<component name="ChangeListManager">
<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$/.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>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -36,21 +41,21 @@
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"ASKED_ADD_EXTERNAL_FILES": "true",
"RunOnceActivity.OpenDjangoStructureViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"git-widget-placeholder": "main",
"node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true",
"node.js.selected.package.eslint": "(autodetect)",
"node.js.selected.package.tslint": "(autodetect)",
"nodejs_package_manager_path": "npm",
"settings.editor.selected.configurable": "com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable",
"vue.rearranger.settings.migration": "true"
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;ASKED_ADD_EXTERNAL_FILES&quot;: &quot;true&quot;,
&quot;RunOnceActivity.OpenDjangoStructureViewOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;git-widget-placeholder&quot;: &quot;main&quot;,
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
&quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
&quot;settings.editor.selected.configurable&quot;: &quot;com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable&quot;,
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
}
}]]></component>
}</component>
<component name="RunManager">
<configuration name="tJango" type="Python.DjangoServer" factoryName="Django server">
<module name="tJango" />
@ -95,6 +100,7 @@
<updated>1719511805110</updated>
<workItem from="1719511812328" duration="309000" />
<workItem from="1719512143097" duration="830000" />
<workItem from="1719617813873" duration="422000" />
</task>
<servers />
</component>

View file

@ -1,4 +1,7 @@
{
"python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python",
"python.analysis.indexing": true,
"python.analysis.packageIndexDepths":[["rest_framework", 5, true]],
"cSpell.words": [
"viewsets"
]

Binary file not shown.

View file

@ -38,6 +38,8 @@ INSTALLED_APPS = [
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'hello',
'user',
]
REST_FRAMEWORK = {

View file

@ -17,23 +17,17 @@ Including another URLconf
from django.contrib import admin
from django.urls import path, include
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):
queryset = User.objects.all()
serializer_class = UserSerializer
router = routers.DefaultRouter()
router = DefaultRouter()
router.register(r'users', UserViewSet)
urlpatterns = [
path('api-auth/', include('rest_framework.urls')),
path('hello', include("hello.urls")),
path('hello/', include("hello.urls")),
path('', include(router.urls)),
path('admin/', admin.site.urls),
path('user/', include((router.urls, 'user'), namespace='user'))
]

0
user/__init__.py Normal file
View file

5
user/admin.py Normal file
View 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
View file

@ -0,0 +1,6 @@
from django.apps import AppConfig
class UserConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'user'

View 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)),
],
),
]

View file

12
user/models.py Normal file
View 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
View 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
View file

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

16
user/views.py Normal file
View 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())