Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
inc. + auto tags + form simple validation + auto reverse redirect after form submitted & inserted to db
- Loading branch information
1 parent
556a8d3
commit 5b9e48a
Showing
8 changed files
with
77 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
from django.core.urlresolvers import reverse | ||
from django.db import models | ||
|
||
|
||
|
||
class Post(models.Model): # this will create a table "blog_post" in small letter format: "<app_name>_<class_name>" | ||
title = models.CharField(max_length = 140) # optional max_length | ||
body = models.TextField() | ||
date = models.DateTimeField() | ||
|
||
def get_absolute_url(self): | ||
return reverse('blog2:detail', kwargs={'pk': self.pk}) # form inserted into db, then redirect to this url. | ||
|
||
def __str__(self): | ||
return self.title | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<title>{% block title %}{% endblock %}</title> | ||
<meta charset="utf-8" /> | ||
{% load staticfiles %} | ||
<link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}" type = "text/css"/> | ||
<meta name="viewport" content = "width=device-width, initial-scale=1.0"> | ||
|
||
<style type="text/css"> | ||
html, | ||
body { | ||
height:100% | ||
} | ||
</style> | ||
</head> | ||
|
||
<body class="body"> | ||
{% block body %} | ||
|
||
{% endblock %} | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{% for field in form %} | ||
<div class="form-group"> | ||
<div class="col-sm-10 col-sm-offset-2"> | ||
<span class="text-danger small"> | ||
{{ field.errors }} | ||
</span> | ||
</div> | ||
<label class="control-label col-sm-2"> | ||
{{ field.label_tag }} | ||
</label> | ||
<div class="col-sm-10">{{ field }}</div> | ||
</div> | ||
{% endfor %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{% extends "blog2/base.html" %} | ||
|
||
{% block body %} | ||
<div class="container-fluid"> | ||
<div class="row"> | ||
<div class="col-sm-12 col-md-7"> | ||
<div class="panel panel-default"> | ||
<div class="panel-body"> | ||
|
||
<form class="form-horizontal" action="" method="post" enctype="multipart/form-data"> | ||
{% csrf_token %} | ||
{% include "blog2/form_template.html"%} | ||
<div class="form-group"> | ||
<div class="col-sm-10 col-sm-offset-2"> | ||
<button type="submit" class="btn btn-success">Submit</button> | ||
</div> | ||
</div> | ||
</form> | ||
|
||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters