Commit af97df63 authored by Bianca Aguilar's avatar Bianca Aguilar

Tracking files

parent cd60715c
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, WidgetUser
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'),
),
]
from tkinter import Widget
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.DateTimeField("Date Published", auto_now=True)
author = models.ForeignKey(
WidgetUser,
on_delete=models.CASCADE,
null=True,
)
def __str__(self): def __str__(self):
return '{}'.format(self.post_title) return '{}'.format(self.post_title)
\ No newline at end of file
@property
def post_detail(self):
post = '{} by {} {} dated {}:'.format(self.post_title, self.author.first_name, self.author.last_name, self.pub_date)
post += '<br>{}'.format(self.post_body)
return post
def get_absolute_url(self):
return reverse('post_detail', args=[str(self.pub_date)])
class Reply(models.Model):
reply_body = models.CharField(max_length=500)
pub_date = models.DateTimeField("Date Published", auto_now=True)
author = models.ForeignKey(
WidgetUser,
on_delete=models.CASCADE,
null=True,
)
def __str__(self):
return 'Reply dated {}'.format(self.pub_date)
@property
def reply_detail(self):
reply = 'Reply by {} {} dated {}:'.format(self.author.first_name, self.author.last_name, self.pub_date)
reply += '<br>{}'.format(self.reply_body)
return reply
def get_absolute_url(self):
return reverse('reply_detail', args=[str(self.pub_date)])
from django.http import HttpResponse from django.http import HttpResponse
from .models import Post
# 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)
return final_list
html = f'''
<html>
<body>
<h1>FORUM POSTS:</h1>
<p>{post_list()}</p>
</body>
</html>
'''
return HttpResponse(html)
...@@ -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