farmaseftika model va api qoshildi
This commit is contained in:
@@ -5,4 +5,5 @@ from .pharmacy import *
|
||||
from .doctor import *
|
||||
from .plan import *
|
||||
from .tour_plan import *
|
||||
from .location import *
|
||||
from .location import *
|
||||
from .factory import *
|
||||
11
core/apps/shared/admin/factory.py
Normal file
11
core/apps/shared/admin/factory.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from django.contrib import admin
|
||||
|
||||
|
||||
# shared
|
||||
from core.apps.shared.models import Factory
|
||||
|
||||
|
||||
|
||||
@admin.register(Factory)
|
||||
class FactoryAdmin(admin.ModelAdmin):
|
||||
list_display = ['id', 'name']
|
||||
25
core/apps/shared/migrations/0010_factory.py
Normal file
25
core/apps/shared/migrations/0010_factory.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# Generated by Django 5.2 on 2025-11-27 10:12
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('shared', '0009_remove_tourplan_district_tourplan_location_send_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Factory',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
('name', models.CharField(max_length=200)),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
]
|
||||
@@ -6,4 +6,5 @@ from .doctor import *
|
||||
from .pharmacy import *
|
||||
from .plan import *
|
||||
from .location import *
|
||||
from .tour_plan import *
|
||||
from .tour_plan import *
|
||||
from .factory import *
|
||||
|
||||
13
core/apps/shared/models/factory.py
Normal file
13
core/apps/shared/models/factory.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from django.db import models
|
||||
|
||||
# shared
|
||||
from core.apps.shared.models import BaseModel
|
||||
|
||||
|
||||
class Factory(BaseModel):
|
||||
name = models.CharField(max_length=200)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
14
core/apps/shared/serializers/factory.py
Normal file
14
core/apps/shared/serializers/factory.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from rest_framework import serializers
|
||||
|
||||
|
||||
# shared
|
||||
from core.apps.shared.models import Factory
|
||||
|
||||
|
||||
|
||||
class FactorySerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Factory
|
||||
fields = [
|
||||
'id', 'name', 'created_at'
|
||||
]
|
||||
@@ -16,6 +16,8 @@ from core.apps.shared.views import plan as plan_view
|
||||
from core.apps.shared.views import location as location_view
|
||||
# shared tour plan view
|
||||
from core.apps.shared.views import tour_plan as tp_view
|
||||
# shared factory view
|
||||
from core.apps.shared.views import factory as factory_view
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
@@ -74,5 +76,10 @@ urlpatterns = [
|
||||
[
|
||||
path('list/', tp_view.TourPlanListApiView.as_view(), name='tour-plan-list-api'),
|
||||
]
|
||||
))
|
||||
)),
|
||||
path('factory/', include(
|
||||
[
|
||||
path('list/', factory_view.FactoryListApiView.as_view(), name='factory-list-api'),
|
||||
],
|
||||
)),
|
||||
]
|
||||
80
core/apps/shared/views/factory.py
Normal file
80
core/apps/shared/views/factory.py
Normal file
@@ -0,0 +1,80 @@
|
||||
# rest framework
|
||||
from rest_framework import generics, permissions
|
||||
|
||||
# drf yasg
|
||||
from drf_yasg import openapi
|
||||
from drf_yasg.utils import swagger_auto_schema
|
||||
|
||||
# shared
|
||||
from core.apps.shared.models import Factory
|
||||
from core.apps.shared.utils.response_mixin import ResponseMixin
|
||||
from core.apps.shared.serializers.factory import FactorySerializer
|
||||
|
||||
|
||||
class FactoryListApiView(generics.GenericAPIView, ResponseMixin):
|
||||
serializer_class = FactorySerializer
|
||||
queryset = Factory.objects.all()
|
||||
permission_classes = [permissions.IsAuthenticated]
|
||||
|
||||
@swagger_auto_schema(
|
||||
tags=["Farmaseftika"],
|
||||
operation_description='Farmasevtikani listini olish uchun api',
|
||||
manual_parameters=[
|
||||
openapi.Parameter(
|
||||
name='search',
|
||||
in_=openapi.IN_QUERY,
|
||||
description='Nomi boyicha qidirish',
|
||||
type=openapi.TYPE_STRING,
|
||||
required=False,
|
||||
)
|
||||
],
|
||||
responses={
|
||||
200: openapi.Response(
|
||||
schema=None,
|
||||
description='Success',
|
||||
examples={
|
||||
"application/json": {
|
||||
"status_code": 200,
|
||||
"status": "success",
|
||||
"message": "malumotlar fetch qilindi",
|
||||
"data": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "string",
|
||||
"created_at": "string",
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
),
|
||||
500: openapi.Response(
|
||||
schema=None,
|
||||
description="Server Error",
|
||||
examples={
|
||||
"application/json": {
|
||||
"status_code": 500,
|
||||
"status": "success",
|
||||
"message": "xatolik",
|
||||
"data": "string",
|
||||
}
|
||||
}
|
||||
),
|
||||
}
|
||||
)
|
||||
def get(self, request):
|
||||
try:
|
||||
query = self.queryset.order_by('-created_at')
|
||||
search = request.query_params.get('search')
|
||||
if search:
|
||||
query = query.filter(name__istartswith=search)
|
||||
|
||||
serializer = self.serializer_class(query, many=True)
|
||||
return self.success_response(
|
||||
data=serializer.data,
|
||||
message='malumotlar fetch qilindi'
|
||||
)
|
||||
except Exception as e:
|
||||
return self.error_response(
|
||||
data=str(e),
|
||||
message='xatolik'
|
||||
)
|
||||
Reference in New Issue
Block a user