Fixing merge errors in local repo

parent 09bdae46
No preview for this file type
import os, sys; sys.path.append(os.path.dirname(os.path.realpath(__file__)))
\ No newline at end of file
from django.contrib import admin from django.contrib import admin
# Register your models here. # Register your models here.
from .models import Post from .models import Post, Reply
class PostAdmin(admin.ModelAdmin): class PostAdmin(admin.ModelAdmin):
model = Post model = Post
class ReplyAdmin(admin.ModelAdmin):
model = Reply
admin.site.register(Post, PostAdmin) admin.site.register(Post, PostAdmin)
admin.site.register(Reply, ReplyAdmin)
\ No newline at end of file
# Generated by Django 4.0.3 on 2022-04-04 06:25
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('homepage', '0001_initial'),
('forum', '0003_alter_post_pub_date'),
]
operations = [
migrations.AddField(
model_name='post',
name='author',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='posts', to='homepage.widgetuser'),
),
migrations.CreateModel(
name='Reply',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('reply_body', models.CharField(max_length=500)),
('pub_date', models.DateTimeField(auto_now=True, verbose_name='Date Published')),
('author', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='replies', to='homepage.widgetuser')),
],
),
]
# Generated by Django 4.0.3 on 2022-04-04 16:06
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('homepage', '0001_initial'),
('forum', '0004_post_author_reply'),
]
operations = [
migrations.AlterField(
model_name='post',
name='author',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='homepage.widgetuser'),
),
migrations.AlterField(
model_name='reply',
name='author',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='homepage.widgetuser'),
),
]
# Generated by Django 4.0.3 on 2022-04-04 17:31
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('homepage', '0003_widgetuser_department'),
('forum', '0005_alter_post_author_alter_reply_author'),
]
operations = [
migrations.AlterField(
model_name='post',
name='author',
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='homepage.widgetuser'),
preserve_default=False,
),
migrations.AlterField(
model_name='reply',
name='author',
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='homepage.widgetuser'),
preserve_default=False,
),
]
# Generated by Django 4.0.3 on 2022-04-05 04:49
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('forum', '0006_alter_post_author_alter_reply_author'),
]
operations = [
migrations.AlterField(
model_name='post',
name='pub_date',
field=models.DateTimeField(auto_now=True),
),
migrations.AlterField(
model_name='reply',
name='pub_date',
field=models.DateTimeField(auto_now=True),
),
]
# Generated by Django 4.0.3 on 2022-04-05 05:44
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('forum', '0007_alter_post_pub_date_alter_reply_pub_date'),
]
operations = [
migrations.AddField(
model_name='reply',
name='post',
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, related_name='comments', to='forum.post'),
preserve_default=False,
),
migrations.AlterField(
model_name='post',
name='pub_date',
field=models.DateField(auto_now=True),
),
migrations.AlterField(
model_name='reply',
name='pub_date',
field=models.DateField(auto_now=True),
),
]
# Generated by Django 4.0.3 on 2022-04-05 05:47
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('forum', '0008_reply_post_alter_post_pub_date_alter_reply_pub_date'),
]
operations = [
migrations.AlterField(
model_name='post',
name='pub_date',
field=models.DateTimeField(auto_now=True),
),
migrations.AlterField(
model_name='reply',
name='pub_date',
field=models.DateTimeField(auto_now=True),
),
]
# Generated by Django 4.0.3 on 2022-04-05 05:49
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('forum', '0009_alter_post_pub_date_alter_reply_pub_date'),
]
operations = [
migrations.AlterField(
model_name='post',
name='pub_date',
field=models.DateField(auto_now=True),
),
migrations.AlterField(
model_name='reply',
name='pub_date',
field=models.DateField(auto_now=True),
),
]
from django.db import models from django.db import models
from django.urls import reverse
from homepage.models import WidgetUser
# Create your models here. # Create your models here.
class Post(models.Model): class Post(models.Model):
post_title = models.CharField(max_length=50) post_title = models.CharField(max_length=50)
post_body = models.CharField(max_length=500) post_body = models.CharField(max_length=500)
pub_date = models.DateTimeField("Date Published", auto_now=True) pub_date = models.DateField(auto_now=True)
author = models.ForeignKey(
'homepage.WidgetUser',
on_delete=models.CASCADE
)
def __str__(self): def __str__(self):
return '{}'.format(self.post_title) return '{}'.format(self.post_title)
@property
def post_detail(self):
post = '<br>{} by {} dated {}:'.format(self.post_title, self.author.forum_name, self.pub_date)
post += '<br>{}'.format(self.post_body)
return post
class Reply(models.Model):
reply_body = models.CharField(max_length=500)
pub_date = models.DateField(auto_now=True)
author = models.ForeignKey(
'homepage.WidgetUser',
on_delete=models.CASCADE
)
post = models.ForeignKey(
Post,
on_delete=models.CASCADE,
related_name="comments"
)
def __str__(self):
return 'Reply dated {}'.format(self.pub_date)
@property
def reply_detail(self):
reply = '<br>Reply by {} {} dated {}:'.format(self.author.first_name, self.author.last_name, self.pub_date)
reply += '<br>{}'.format(self.reply_body)
return reply
@property
def associated_post(self):
return '{}'.format(self.post.__str__)
from django.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse
from .models import Post, Reply
# Create your views here. # Create your views here.
def index(request): def index(request):
return HttpResponse("Welcome to Widget's Forum!") def post_list():
final_list = ''
for p in range(len(Post.objects.all())):
final_list += '{}'.format(Post.objects.get(pk=p+1).post_detail)
reply_list = Post.objects.get(pk=p+1).comments.all()
for r in range(len(reply_list)):
final_list += '{}'.format(Reply.objects.get(post__exact=Post.objects.get(pk=p+1)).reply_detail)
return final_list
html = f'''
<html>
<body>
<h1>FORUM POSTS:</h1>
<main>
<p>{post_list()}</p>
</main>
</body>
</html>
'''
return HttpResponse(html)
...@@ -19,10 +19,14 @@ class WidgetUser(models.Model): ...@@ -19,10 +19,14 @@ class WidgetUser(models.Model):
department = models.ForeignKey(Department, on_delete = models.CASCADE) department = models.ForeignKey(Department, on_delete = models.CASCADE)
@property def __str__(self):
def full_name(self):
return '{}, {} {}'.format(self.last_name, self.first_name, self.middle_name) return '{}, {} {}'.format(self.last_name, self.first_name, self.middle_name)
@property
def forum_name(self):
return '{} {}'.format(self.first_name, self.last_name)
@property @property
def user_info(self): def user_info(self):
return '<br>{}: {}, {}, {}'.format(self.full_name, self.id_num, self.email, self.department.dept_info) return '<br>{}: {}, {}, {}'.format(self.__str__, self.id_num, self.email, self.department.dept_info)
\ No newline at end of file \ No newline at end of file
from django.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse
from .models import WidgetUser from .models import WidgetUser
......
...@@ -62,7 +62,7 @@ ROOT_URLCONF = 'widget_group_23.urls' ...@@ -62,7 +62,7 @@ ROOT_URLCONF = 'widget_group_23.urls'
TEMPLATES = [ TEMPLATES = [
{ {
'BACKEND': 'django.template.backends.django.DjangoTemplates', 'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [], 'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True, 'APP_DIRS': True,
'OPTIONS': { 'OPTIONS': {
'context_processors': [ 'context_processors': [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment