reg: creating blog topic in database

25 views
Skip to first unread message

Amitesh Sahay

unread,
Nov 16, 2019, 4:40:59 AM11/16/19
to Django Users
Hello All,

I have created the two models to create post on desired topic, as well as to get the comments from the visitors. But, I am not able to figure out, how to connect that model to my HTML page.

I know how to create a static HTML pages for each topic,and write page content in <p></p> tags. which I have been thinking to do until now, but it seems to be a time taking and non-productive way. So, now I would like to write posts in my database model which I have registered in admin.py.

Any idea, how can I achieve this, as this would be a like generating dynamic HTML pages based on models.

I am not sure if I was able to explain my requirements. May be as I am not getting right words to express them. Please ask me questions if any confusion, I will try to answer them.

Below is my models.py

from django.db import models
from django.utils import timezone
from django.contrib.auth.models import User


class Post(models.Model):
STATUS_CHOICES = (
('draft', 'Draft'),
('published', 'Published'),
)
title = models.CharField(max_length=250)
slug = models.SlugField(max_length=250, unique_for_date='publish')
author = models.ForeignKey(User, related_name='blog_posts', on_delete=models.CASCADE)
body = models.TextField()
publish = models.DateTimeField(default=timezone.now)
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
status = models.CharField(max_length=10, choices=STATUS_CHOICES, default='draft')

class Meta:
ordering = ('-publish',)

def __str__(self):
return self.title


class Comment(models.Model):
post = models.ForeignKey(Post, related_name='comments', on_delete=models.CASCADE)
name = models.CharField(max_length=80)
email = models.EmailField()
body = models.TextField()
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
active = models.BooleanField(default=True)

class Meta:
ordering = ('created',)

def __str__(self):
return self.email
Regards,
Amitesh

Integr@te System

unread,
Nov 16, 2019, 6:31:06 AM11/16/19
to django...@googlegroups.com
Hi Issuer

Follow to part 3 - 4 and check docs for some thing else around you need


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1799372727.1057468.1573897086523%40mail.yahoo.com.

Amitesh Sahay

unread,
Nov 18, 2019, 7:57:30 AM11/18/19
to django...@googlegroups.com
Hi,

To be honest, I have tried following the django docs link that you have shared. But I failed to understand the relevance . I have little knowledge. So, I might be little clueless here.

Regards,
Amitesh


Amitesh Sahay

unread,
Nov 19, 2019, 8:00:24 AM11/19/19
to django...@googlegroups.com
I have got a work around though, and yes, those two links were handy.

Regards,
Amitesh


Reply all
Reply to author
Forward
0 new messages