Initial Commit
This commit is contained in:
commit
e08aac9aad
17 changed files with 142 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
django_tags*
|
0
LICENSE
Normal file
0
LICENSE
Normal file
4
MANIFEST.in
Normal file
4
MANIFEST.in
Normal file
|
@ -0,0 +1,4 @@
|
|||
include LICENSE
|
||||
include README.md
|
||||
recursive-include docs *
|
||||
recursive-include tags/templates *
|
3
README.md
Normal file
3
README.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
# Jeff Django tags
|
||||
|
||||
This is a simple app that allows us to create tags and then tag any entity within the project.
|
BIN
dist/django-tags-0.1.tar.gz
vendored
Normal file
BIN
dist/django-tags-0.1.tar.gz
vendored
Normal file
Binary file not shown.
3
pyproject.toml
Normal file
3
pyproject.toml
Normal file
|
@ -0,0 +1,3 @@
|
|||
[build-system]
|
||||
requires = ['setuptools>=40.8.0']
|
||||
build-backend = 'setuptools.build_meta'
|
33
setup.cfg
Normal file
33
setup.cfg
Normal file
|
@ -0,0 +1,33 @@
|
|||
[metadata]
|
||||
name = django-tags
|
||||
version = 0.1
|
||||
description = A Django app to tag entities.
|
||||
long_description = file: readme.md
|
||||
url = https://www.jeffmackinnon.com/pages/apps.html
|
||||
author = Jeff MacKinnon
|
||||
author_email = jeff@fastmail.in
|
||||
license = BSD-3-Clause
|
||||
classifiers =
|
||||
Environment :: Web Environment
|
||||
Framework :: Django
|
||||
Framework :: Django :: 4.2
|
||||
Intended Audience :: Developers
|
||||
License :: OSI Approved :: BSD License
|
||||
Operating System :: OS Independent
|
||||
Programming Language :: Python
|
||||
Programming Language :: Python :: 3
|
||||
Programming Language :: Python :: 3 :: Only
|
||||
Programming Language :: Python :: 3.8
|
||||
Programming Language :: Python :: 3.9
|
||||
Programming Language :: Python :: 3.10
|
||||
Programming Language :: Python :: 3.11
|
||||
Programming Language :: Python :: 3.12
|
||||
Topic :: Internet :: WWW/HTTP
|
||||
Topic :: Internet :: WWW/HTTP :: Dynamic Content
|
||||
|
||||
[options]
|
||||
include_package_data = true
|
||||
packages = find:
|
||||
python_requires = >=3.8
|
||||
install_requires =
|
||||
Django >= 4.2
|
3
setup.py
Normal file
3
setup.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from setuptools import setup
|
||||
|
||||
setup()
|
0
tags/__init__.py
Normal file
0
tags/__init__.py
Normal file
13
tags/admin.py
Normal file
13
tags/admin.py
Normal file
|
@ -0,0 +1,13 @@
|
|||
from django.contrib import admin
|
||||
from . import models
|
||||
|
||||
# Register your models here.
|
||||
|
||||
@admin.register(models.Tag)
|
||||
class TagAdmin(admin.ModelAdmin):
|
||||
list_display = ['label', 'type']
|
||||
list_editable = ['type']
|
||||
|
||||
@admin.register(models.TaggedItem)
|
||||
class TaggedAdmin(admin.ModelAdmin):
|
||||
list_display = ['tag', 'content_type', 'content_object', 'tagged']
|
6
tags/apps.py
Normal file
6
tags/apps.py
Normal file
|
@ -0,0 +1,6 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class TagsConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'tags'
|
9
tags/forms.py
Normal file
9
tags/forms.py
Normal file
|
@ -0,0 +1,9 @@
|
|||
from django import forms
|
||||
from .models import Tag
|
||||
|
||||
class TagForm(forms.ModelForm):
|
||||
|
||||
class Meta:
|
||||
model = Tag
|
||||
fields = ['label', 'type']
|
||||
labels = {'label':'New Tag', 'type':'Tag Type'}
|
29
tags/models.py
Normal file
29
tags/models.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
from django.db import models
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.contrib.contenttypes.fields import GenericForeignKey
|
||||
|
||||
|
||||
# Create your models here.
|
||||
|
||||
class Tag(models.Model):
|
||||
label = models.CharField(max_length=255)
|
||||
type = models.CharField(max_length=255, default=None, null=True, blank=True)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.label
|
||||
|
||||
|
||||
|
||||
class TaggedItem(models.Model):
|
||||
"""
|
||||
This keeps track of the generic items that are tagged and when they were tagged.
|
||||
|
||||
The time is important because when a profile is tagged
|
||||
Public and then is changed to -> Private all information past that point is not going to be shared.
|
||||
|
||||
"""
|
||||
tag = models.ForeignKey(Tag, on_delete=models.CASCADE)
|
||||
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
|
||||
object_id = models.PositiveIntegerField()
|
||||
content_object = GenericForeignKey()
|
||||
tagged = models.DateTimeField(auto_now_add=True)
|
10
tags/templates/tags/list.html
Normal file
10
tags/templates/tags/list.html
Normal file
|
@ -0,0 +1,10 @@
|
|||
{% block content %}
|
||||
<h1>All the tags</h1>
|
||||
|
||||
<ul>
|
||||
{% for tag in tags %}
|
||||
<li>{{ tag.label }} - {{ tag.type }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
{% endblock %}
|
3
tags/tests.py
Normal file
3
tags/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
11
tags/urls.py
Normal file
11
tags/urls.py
Normal file
|
@ -0,0 +1,11 @@
|
|||
from django.urls import path
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path('', views.TagsListView.as_view(), name="tags.list"),
|
||||
# path('tags/<int:pk>', views.TagsDetailView.as_view(), name="tags.detail"),
|
||||
#path('tags/<int:pk>/edit', views.TagsUpdateView.as_view(), name="tags.update"),
|
||||
#path('tags/<int:pk>/delete', views.TagsDeleteView.as_view(), name="tags.delete"),
|
||||
#path('tags/new', views.TagsCreateView.as_view(), name="tags.new"),
|
||||
|
||||
]
|
14
tags/views.py
Normal file
14
tags/views.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
from django.shortcuts import render
|
||||
from django.views.generic import ListView
|
||||
|
||||
from .models import Tag
|
||||
#from .forms import TagForm
|
||||
|
||||
# Create your views here.
|
||||
class TagsListView(ListView):
|
||||
model = Tag
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
tags = Tag.objects.all()
|
||||
context = {'tags':tags}
|
||||
return render(request, 'tags/list.html', context)
|
Loading…
Reference in a new issue