P-92
This commit is contained in:
1 parent
980b6024c6
commit
63fdfa8836
3 files changed
+22
-18
No files matched your search
+13
-8
@@ -48,8 +48,9 @@ class VoteDetail(generics.RetrieveUpdateDestroyAPIView):
|
||||
lookup_url_kwarg = 'id'
|
||||
lookup_field = 'id'
|
||||
|
||||
class VoteCreate(APIView):
|
||||
import json
|
||||
|
||||
class VoteCreate(APIView):
|
||||
def post(self, request):
|
||||
user = request.user
|
||||
user = DictEmployee.objects.get(login='9966-00-125')
|
||||
@@ -63,17 +64,21 @@ class VoteCreate(APIView):
|
||||
author=user,
|
||||
)
|
||||
vote.save()
|
||||
|
||||
for count, question_data in enumerate(request.data['questions'], start=1):
|
||||
|
||||
questions = json.loads(request.data['questions'])
|
||||
for count, question_data in enumerate(questions, start=1):
|
||||
question = Question(
|
||||
question=question_data['text'],
|
||||
vote=vote,
|
||||
# file=question.get('image', None),
|
||||
file = request.FILES.get('image'),
|
||||
file=request.FILES.get('image'),
|
||||
numb=count,
|
||||
)
|
||||
question.save()
|
||||
for answer in question_data['answers']:
|
||||
Answer(answer=answer['text'], file=request.FILES.get('image'), question=question).save()
|
||||
|
||||
return Response({'status': 'success', 'message': 'Vote created successfully.'}, status=201)
|
||||
Answer(
|
||||
answer=answer['text'],
|
||||
file=request.FILES.get('image'),
|
||||
question=question
|
||||
).save()
|
||||
|
||||
return Response({'status': 'success', 'message': 'Vote created successfully.'}, status=201)
|
||||
@@ -249,7 +249,7 @@
|
||||
|
||||
<script>
|
||||
import {computed, ref} from "vue";
|
||||
import {createVote} from "@/utils/axios-api";
|
||||
import {createVote, getVotes} from "@/utils/axios-api";
|
||||
|
||||
export default {
|
||||
setup() {
|
||||
@@ -317,6 +317,13 @@ export default {
|
||||
const response = await createVote(form.value);
|
||||
console.log("Голосование успешно создано:", response);
|
||||
isVoteCreated.value = true;
|
||||
getVotes('active')
|
||||
.then(data => {
|
||||
console.log('Активные голосования:', data);
|
||||
})
|
||||
.catch(err => {
|
||||
console.error('Ошибка:', err);
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Ошибка при создании голосования:", error);
|
||||
}
|
||||
|
||||
@@ -122,20 +122,12 @@ async function createVote(voteData, files) {
|
||||
formData.append('description', voteData.description);
|
||||
formData.append('startDate', new Date(voteData.startDate).toISOString());
|
||||
formData.append('endDate', new Date(voteData.endDate).toISOString());
|
||||
formData.append('questions', voteData.questions);
|
||||
formData.append('questions', JSON.stringify(voteData.questions));
|
||||
|
||||
const response = await axiosApiInstance.post('/api/vote/votecreate/', formData, {
|
||||
headers: { 'Content-Type': 'multipart/form-data' },
|
||||
});
|
||||
|
||||
getVotes('active')
|
||||
.then(data => {
|
||||
console.log('Активные голосования:', data);
|
||||
})
|
||||
.catch(err => {
|
||||
console.error('Ошибка:', err);
|
||||
});
|
||||
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.error('Ошибка создания голосования:', error);
|
||||
|
||||
Reference in new issue
Block a user