-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/sipe-team/sipethon-3_6_ains…
- Loading branch information
Showing
20 changed files
with
178 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class AnswerConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "apps.answer" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from ninja import FilterSchema | ||
|
||
|
||
class AnswerFilter(FilterSchema): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Generated by Django 5.1.5 on 2025-01-18 02:43 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='UserAnswer', | ||
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)), | ||
('question', models.CharField(max_length=150)), | ||
], | ||
options={ | ||
'db_table': 'user_answer', | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='ModelAnswer', | ||
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)), | ||
('model_name', models.CharField(max_length=20)), | ||
('answer', models.TextField()), | ||
('user_answer', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, related_name='model_answers', to='answer.useranswer')), | ||
], | ||
options={ | ||
'db_table': 'model_answer', | ||
}, | ||
), | ||
] |
18 changes: 18 additions & 0 deletions
18
apps/answer/migrations/0002_rename_model_name_modelanswer_model_id.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 5.1.5 on 2025-01-18 05:05 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('answer', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.RenameField( | ||
model_name='modelanswer', | ||
old_name='model_name', | ||
new_name='model_id', | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from contrib.django import models | ||
|
||
|
||
|
||
class UserAnswer(models.BaseDateTimeModel): | ||
question = models.CharField(max_length=150) | ||
|
||
class Meta: | ||
db_table = 'user_answer' | ||
|
||
|
||
class ModelAnswer(models.BaseDateTimeModel): | ||
model_id = models.CharField(max_length=20) | ||
answer = models.TextField() | ||
user_answer = models.ForeignKey('answer.UserAnswer', on_delete=models.DO_NOTHING, related_name='model_answers') | ||
|
||
class Meta: | ||
db_table = 'model_answer' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from ninja import Schema | ||
|
||
|
||
class ModelAnswerSchema(Schema): | ||
model_id: str | ||
answer: str | ||
|
||
|
||
class UserAnswerSchema(Schema): | ||
id: int | ||
question: str | ||
model_answers: list[ModelAnswerSchema] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from ninja import Router | ||
from ninja.pagination import paginate | ||
|
||
from apps.answer.models import UserAnswer | ||
from apps.answer.schemas import UserAnswerSchema | ||
from contrib.django.ninja.pagination import ContribPageNumberPagination | ||
|
||
router = Router(tags=["Answer"]) | ||
|
||
|
||
@router.get('/answers', response=list[UserAnswerSchema]) | ||
@paginate(ContribPageNumberPagination, page_size=4) | ||
def get_answers(request): | ||
answers = UserAnswer.objects.all() | ||
return answers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from django.db.models import * | ||
from .base import BaseDateTimeModel |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from typing import Any | ||
|
||
from django.db.models import QuerySet | ||
from ninja.pagination import PageNumberPagination | ||
|
||
|
||
class ContribPageNumberPagination(PageNumberPagination): | ||
|
||
class Input(PageNumberPagination.Input): | ||
pass | ||
|
||
class Output(PageNumberPagination.Output): | ||
current_page: int | ||
has_next: bool | ||
|
||
def __init__(self, page_size: int = 10) -> None: | ||
super().__init__(page_size) | ||
|
||
def paginate_queryset( | ||
self, queryset: QuerySet, pagination: Input, **params: Any | ||
) -> Any: | ||
offset = (pagination.page - 1) * self.page_size | ||
items = queryset[offset : offset + self.page_size] | ||
count = self._items_count(queryset) | ||
return { | ||
"items": items, | ||
"count": count, | ||
"current_page": pagination.page, | ||
"has_next": self.page_size * pagination.page < count, | ||
} # noqa: E203 | ||
return super().paginate_queryset(queryset, pagination, **params) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters