Creating a comment model
Before we start creating our API, we need to create a database model for the resource that we wish to share. The API we are building will be used to create and retrieve comments using AJAX, so our model will contain all the fields that would be relevant for storing an unauthenticated user's comment on one of our entries.
For our purposes, the following fields should be sufficient:
name
, the name of the person making the commentemail
, the e-mail address of the person commenting, which we will use solely to display an image of them from GravatarURL
, the URL to the commenters blogip_address
, the IP address of the commenterbody
, the actual commentstatus
, one of eitherPublic
,Spam,
orDeleted
created_timestamp
, the timestamp with which the comment was createdentry_id
, the ID of blog entry the comment relates to
Lets begin coding by creating the Comment model definition in our app's models.py
module:
class Comment(db.Model): STATUS_PENDING_MODERATION = 0 ...