Attention! For non-authenticated users this application provides only existing content review, such as questions and their answers. More features are available only for registered and authenticated users.
Live version: https://vbaforum.up.railway.app/
Thanks django built-in User class, creating new user object is quite easy, but application 'account' extends basic user model by adding new fields in UserProfile custom model, such as:
- avatar - profile picture, (every time once new user instance is creating, the default picture is set up for this field)
- role - closed list of roles that user is able to choose for account
- bio - additional information about user, not required field
- stop_notification - a boolean field that indicates if user wants to get email notification if someone adds answers to question that given user posted
- following - a many to many relation field that creates new relations table in database for storing scope of followers and following users
__str__
for describe instances in admin panel correctly and custom instance method display_fullname_user_role
to make easier to display full name role of each instance.
class UserProfile(models.Model):
user = models.OneToOneField(
User,
on_delete=models.CASCADE,
primary_key = True)
bio = models.TextField(max_length=500, blank=True)
roles = [
("DEV", "developer"),
("STU", "student"),
("INT", "internship"),
("MAN", "project manager"),
("EMP", "employer"),
("TEC", "teacher"),
("OTH", "other"),
("ADM", "admin"),
]
role = models.CharField(
max_length=3,
choices=roles,
default="ADM"
)
avatar = models.ImageField(upload_to="images/", default="images/default_user_img_nnlwnz.jpg")
stop_notifications = models.BooleanField(default=False,
help_text= "if user wants to turn off email notification when question has been answered")
following = models.ManyToManyField(User, blank=True, related_name="following")
@receiver(post_save, sender=User)
def create_user_profile(sender, instance, created, **kwargs):
if created:
UserProfile.objects.create(user=instance)
@receiver(post_save, sender=User)
def save_user_profile(sender, instance, **kwargs):
instance.userprofile.save()
def __str__(self):
return f"{self.user}"
def display_fullname_user_role(self):
for short, long in self.roles:
if self.role == short:
return long
In order to register, new user needs fo fill out below form with correct data:
In case of successully registration, it creates new inactive instance of user and UserProfile accordingly. To activate your account and make possible to use the Forum, you will get a request to go to your mailbox, you provided on registration, and just click in proper button on message body.
The path looks as follows:
However, if you provide username that already exists in database, email you provided is already taken by another user, or your password doesn't satisfy requirements, proper message will be displayed.
Once your are not anonymous user anymore (after log in), it is possible to glimpse your profile. By default, it looks following:
- Basic user information from both User and UserProfile tables in database
- Default profile picture
- Reminder from backend will be visible untile you provide your bio
- Three options of account management
- Change password
- Update profile properties
- Delete account
You can easily change password just by submitting below form:
If data you provided is correct, an prover message will be returned:
In case you put wrong old password or new one doesn't satisfy requirements, user will be informed about that fact.
User is able to change for their account following properties:
- Username
- email address
- role
- profile picture
- provide bio
- stop notification (if stop notification is
True
, user will not receive notifications if someone answers his question on the forum)
After modification, user profile page shows up to date informations. For this example, I updated:
- role - from student to developer
- profile picture - from default to custom
- bio
- turned off email notifications
Logging out user and permanently delete their profile with all related content included.
Below pop up window will be displayed before the action is complete:
All of authenticated users are allowed to both create, read, update and delete content, which means they can post new questions and comment them, edit body of content they created or just remove them.
User can post new question just by filling out proper form on NEW QUEST nabvar tab
Each question instance is composed of:
- Subject
- Text, problem description in details
- Code example and image - not required fields
- Tags
Once question is already posted, it will be visible on the wall with informations: who and when submitted that question, title and beginning of the text body, tags and how many thumbs and comments particular question has.
To go to question details, just click on them directly, then you will be redirected to html template with all that question details and comments, if they are.
Basically, if user is author of specific question, on the bottom there are 3 options (answer, edit and delete), but if you are not author, you can only answer them.
I updated previously added question just by adding picture:
Once action is done, proper message will be displayed:
Currently, updated question has image attached this time (fullsize picture is possible to preview by clicking direcntly on that):
On wall:
Only question author is allowed to remove them just by clicking 'Delete' button.
Every answer is related with specific question thanks question foreign key field in Answer model
question = models.ForeignKey(Question, on_delete=models.CASCADE, related_name="answers")
Adding answer with displaying question you answering to.
Note that CRUD concerns both question and answers content!
Each of authenticated user is able to like both questions and answers, at the same time saving them to quick access collection. Both classes Question
and Answer
have many to many related filed calls likes
. It allows to add simple relationship which is represented in database as 2 columns tables (1st - liked question/answer id, 2nd - user id who like that question/answer).
Quick access tabs are the 2nd and 3rd on the main navbar calls respectively 'Questions' and 'Answer'. Both included content you posted or liked.
Here will be displayed all question/answers that you posted with basic information and management options
Here will be displayed all question/answers that you like with basic information and management options
Thanks filtering database content, user is allowed to browse posted questions by:
- title
- text
- author's username
- tags
Techncally, it is possible thanks advanced queryset filtering:
queryset = Question.objects.filter(
Q(title__icontains = word) |
Q(text__icontains = word) |
Q(user__username__icontains = word) |
Q(tags__name__icontains = word)
Community tab includes 4 main components:
It allows you to find any user with active and non-staff account. Additionally, it counts how many users currently satisfy that requirments. Moreover, searchbar helps to find specific users by filtering using username or role.
A scope of users that you follow.
The backend allows users to send messages from application level. Initially, My conversations is empty, to send message to specific user, it's necessary to open their profile view page.
Messages are displaying by proper sides, it depends who are receiver and sender.