-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
205 additions
and
62 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,7 @@ | |
"event", | ||
"blog", | ||
"poll", | ||
"message" | ||
|
||
] | ||
# AUTH_USER_MODEL = "users.CustomUser" | ||
|
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
File renamed without changes.
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
QUESTION_TYPES = (("PRAYER_REQUEST", "PRAYER_REQUEST"), ("COUNSELLING", "COUNSELLING"), | ||
("OTHERS", "OTHERS"), ("WHISTLEBLOWING", "WHISTLEBLOWING"), ("SUGGESTION", "SUGGESTION")) |
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,33 @@ | ||
# Generated by Django 4.0.8 on 2023-01-21 09:14 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import uuid | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Message', | ||
fields=[ | ||
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), | ||
('created_at', models.DateTimeField(auto_now_add=True)), | ||
('updated_at', models.DateTimeField(auto_now=True)), | ||
('title', models.CharField(max_length=100)), | ||
('body', models.TextField(blank=True)), | ||
('message_type', models.CharField(choices=[], max_length=20)), | ||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='message', to=settings.AUTH_USER_MODEL)), | ||
], | ||
options={ | ||
'ordering': ('-created_at',), | ||
}, | ||
), | ||
] |
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 4.0.8 on 2023-01-21 09:21 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('message', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='message', | ||
name='message_type', | ||
field=models.CharField(choices=[('PRAYER_REQUEST', 'PRAYER_REQUEST'), ('COUNSELLING', 'COUNSELLING'), ('OTHERS', 'OTHERS'), ('WHISTLEBLOWING', 'WHISTLEBLOWING'), ('SUGGESTION', 'SUGGESTION')], max_length=20), | ||
), | ||
] |
File renamed without changes.
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,19 @@ | ||
from django.db import models | ||
from core.models import AuditableModel | ||
from account.models import CustomUser | ||
from .enums import QUESTION_TYPES | ||
# Create your models here. | ||
|
||
|
||
class Message (AuditableModel): | ||
title = models.CharField(max_length=100, blank=False) | ||
user = models.ForeignKey( | ||
CustomUser, on_delete=models.CASCADE, related_name='message') | ||
body = models.TextField(blank=True) | ||
message_type = models.CharField(max_length=20, choices=QUESTION_TYPES) | ||
|
||
class Meta: | ||
ordering = ('-created_at',) | ||
|
||
def __str__(self) -> str: | ||
return self.title |
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 @@ | ||
# django #selenium #webscraping | ||
from rest_framework import serializers | ||
from django.contrib.auth.models import User, Group | ||
from .models import Message | ||
|
||
|
||
class MessageSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Message | ||
# fields = ('id', 'title', 'description', 'completed') | ||
# Shortcut for getting all fields | ||
fields = '__all__' | ||
extra_kwargs = { | ||
'user': {'read_only': True}, | ||
} |
File renamed without changes.
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 rest_framework.routers import DefaultRouter | ||
from django.urls import path, include | ||
from .views import MessageListCreateAPIView, MessageRetrieveAPIView, MessageUpdateAPIView, MessageDestroyAPIView | ||
|
||
urlpatterns = [ | ||
path('<uuid:pk>/', MessageRetrieveAPIView.as_view(), | ||
name="message_detail"), | ||
path('<uuid:pk>/', MessageUpdateAPIView.as_view(), | ||
name="message_update"), | ||
path('<uuid:pk>/', MessageDestroyAPIView.as_view(), | ||
name="message_delete"), | ||
path('', MessageListCreateAPIView.as_view(), name="message_list") | ||
] |
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,27 @@ | ||
from .models import Message | ||
from .serializers import MessageSerializer | ||
from rest_framework import generics | ||
|
||
|
||
class MessageListCreateAPIView(generics.ListCreateAPIView): | ||
queryset = Message.objects.all() | ||
serializer_class = MessageSerializer | ||
|
||
def perform_create(self, serializer): | ||
print(self, "----------", serializer) | ||
serializer.save(user=self.request.user) | ||
|
||
|
||
class MessageRetrieveAPIView(generics.RetrieveAPIView): | ||
queryset = Message.objects.all() | ||
serializer_class = MessageSerializer | ||
|
||
|
||
class MessageUpdateAPIView(generics.UpdateAPIView): | ||
queryset = Message.objects.all() | ||
serializer_class = MessageSerializer | ||
|
||
|
||
class MessageDestroyAPIView(generics.DestroyAPIView): | ||
queryset = Message.objects.all() | ||
serializer_class = MessageSerializer |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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