Skip to content

Commit

Permalink
Create message and comment models
Browse files Browse the repository at this point in the history
  • Loading branch information
fluix-dev committed Sep 19, 2020
1 parent dfdbf44 commit a2d655a
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
24 changes: 24 additions & 0 deletions app/migrations/0014_message.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 3.0.10 on 2020-09-19 23:19

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('app', '0013_auto_20200919_0144'),
]

operations = [
migrations.CreateModel(
name='Message',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('message', models.TextField(blank=True, help_text='Description of this project.', verbose_name='Description')),
('created', models.DateTimeField(auto_now_add=True, help_text='Date this project was created.', verbose_name='Creation Date')),
('from_user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='messages_sent', to='app.Profile')),
('to_user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='messages_received', to='app.Profile')),
],
),
]
30 changes: 30 additions & 0 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from django.dispatch import receiver
from django.urls import reverse
from django.utils import timezone
from mptt import models as mptt_models


class SocialLink(models.Model):
Expand Down Expand Up @@ -270,3 +271,32 @@ def __str__(self):
def create_profile(sender, instance, created, **kwargs):
if created:
Profile.objects.create(user=instance)


class Message(models.Model):
from_user = models.ForeignKey(Profile, related_name="messages_sent", on_delete=models.CASCADE)
to_user = models.ForeignKey(Profile, related_name="messages_received", on_delete=models.CASCADE)
message = models.TextField(
blank=True, verbose_name="Description", help_text="Description of this project."
)
created = models.DateTimeField(
auto_now_add=True, verbose_name="Creation Date", help_text="Date this project was created."
)


class Comment(mptt_models.TreeForeignKey):
author = models.ForeignKey(Profile, related_name="comments", on_delete=models.CASCADE)
parent = mptt_models.TreeForeignKey(
"self", on_delete=models.CASCADE, null=True, blank=True, related_name="children"
)
message = models.TextField(
blank=True, verbose_name="Description", help_text="Description of this project."
)
created = models.DateTimeField(
auto_now_add=True, verbose_name="Creation Date", help_text="Date this project was created."
)
content_type = models.ForeignKey(
ContentType, verbose_name="Linked Item Type", on_delete=models.CASCADE
)
object_id = models.PositiveIntegerField(verbose_name="Linked Item ID")
linked_item = GenericForeignKey()
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ click==7.1.2
Django==3.1
django-colorfield==0.3.2
django-jinja==2.6.0
django-js-asset==1.2.2
django-mptt==0.11.0
Jinja2==2.11.2
MarkupSafe==1.1.1
mistune==2.0.0a4
Expand Down

0 comments on commit a2d655a

Please sign in to comment.