-
-
Notifications
You must be signed in to change notification settings - Fork 622
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Post model and basic listing page
- Loading branch information
Showing
9 changed files
with
98 additions
and
3 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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from django.contrib import admin | ||
from .models import Post | ||
|
||
admin.site.register(Post) |
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,43 @@ | ||
# Generated by Django 5.0.6 on 2024-06-24 12:35 | ||
|
||
import taggit.managers | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
( | ||
"taggit", | ||
"0006_rename_taggeditem_content_type_object_id_taggit_tagg_content_8fc721_idx", | ||
), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="Post", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("title", models.CharField(max_length=200)), | ||
( | ||
"tags", | ||
taggit.managers.TaggableManager( | ||
help_text="A comma-separated list of tags.", | ||
through="taggit.TaggedItem", | ||
to="taggit.Tag", | ||
verbose_name="Tags", | ||
), | ||
), | ||
], | ||
), | ||
] |
Empty file.
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,9 @@ | ||
#!/usr/bin/env python3 | ||
from django.db import models | ||
|
||
from taggit.managers import TaggableManager | ||
|
||
|
||
class Post(models.Model): | ||
title = models.CharField(max_length=200) | ||
tags = TaggableManager(blank=True) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<html> | ||
<title>Sample Taggit App</title> | ||
<body> | ||
<h1>Sample Taggit App</h1> | ||
</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,24 @@ | ||
<html> | ||
<title>Sample Taggit App</title> | ||
<body> | ||
<h1>Sample Taggit App</h1> | ||
|
||
<ul> | ||
{% for post in posts %} | ||
<li> | ||
{{ post.title }} | ||
<br/> | ||
Tags: | ||
{% for tag in post.tags.all %} | ||
{{tag.name}}, | ||
{% empty %} | ||
(None) | ||
{% endfor %} | ||
</li> | ||
{% empty %} | ||
<li>(No posts yet, go to the admin to create some)</li> | ||
{% endfor %} | ||
</ul> | ||
<a href="/admin">Go to admin and manage more data</a> | ||
</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
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,7 @@ | ||
from django.shortcuts import render | ||
|
||
from sample_taggit.models import Post | ||
|
||
|
||
def index_view(request): | ||
return render(request, "index.html", {"posts": Post.objects.all()}) |