Skip to content
This repository has been archived by the owner on Jun 27, 2024. It is now read-only.

Commit

Permalink
WIP(misc): Update tests, migrations and model comments #66
Browse files Browse the repository at this point in the history
  • Loading branch information
imAsparky committed May 8, 2023
1 parent 5e93f00 commit af4f531
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 45 deletions.
4 changes: 2 additions & 2 deletions tag_fields/admin.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from django.contrib import admin

from tag_fields.models import ModelTag, TaggedItem
from tag_fields.models import ModelTag, ModelTagIntFk


class TaggedItemInline(admin.StackedInline):
model = TaggedItem
model = ModelTagIntFk


@admin.register(ModelTag)
Expand Down
4 changes: 2 additions & 2 deletions tag_fields/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from tag_fields.models import (
GenericFKTaggedItemThroughBase,
UUIDFKTaggedItemThroughBase,
TaggedItem,
ModelTagIntFk,
)
from tag_fields.utils import require_instance_manager

Expand Down Expand Up @@ -584,7 +584,7 @@ def __init__(
field_name=None,
manager=_TaggableManager,
):
self.through = through or TaggedItem
self.through = through or ModelTagIntFk

rel = ManyToManyRel(
self, to, related_name=related_name, through=self.through
Expand Down
4 changes: 2 additions & 2 deletions tag_fields/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2 on 2023-05-08 02:07
# Generated by Django 4.2 on 2023-05-08 04:00

from django.db import migrations, models
import django.db.models.deletion
Expand Down Expand Up @@ -26,7 +26,7 @@ class Migration(migrations.Migration):
},
),
migrations.CreateModel(
name='TaggedItem',
name='ModelTagIntFk',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('object_id', models.IntegerField(db_index=True, verbose_name='object ID')),
Expand Down
17 changes: 17 additions & 0 deletions tag_fields/migrations/0002_alter_modeltag_options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2 on 2023-05-08 04:09

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('tag_fields', '0001_initial'),
]

operations = [
migrations.AlterModelOptions(
name='modeltag',
options={'verbose_name': 'Model Tag', 'verbose_name_plural': 'Model Tags'},
),
]
17 changes: 17 additions & 0 deletions tag_fields/migrations/0003_alter_modeltagintfk_options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2 on 2023-05-08 04:10

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('tag_fields', '0002_alter_modeltag_options'),
]

operations = [
migrations.AlterModelOptions(
name='modeltagintfk',
options={'verbose_name': 'Model Tag IntFk', 'verbose_name_plural': 'Model Tags IntFk'},
),
]
29 changes: 10 additions & 19 deletions tag_fields/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def unidecode(tag):
return tag


# Tags base models ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class TagBase(models.Model):
"""Abstract Base class for the tags."""

Expand Down Expand Up @@ -88,29 +89,29 @@ def slugify(self, tag, i=None):
return slug


# Tag models ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class ModelTag(TagBase):
"""Model tag for use with your own model.
This is a model level tag, i.e. there can only be one per model.
taggit class name was Tag
"""

class Meta:
verbose_name = _("tag")
verbose_name_plural = _("tags")
verbose_name = _("Model Tag")
verbose_name_plural = _("Model Tags")
app_label = "tag_fields"


# Through table base models ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class ThroughTableBase(models.Model):
"""Base class for a model ``tags`` through table.
"""Base class for a models ``tags`` through table.
Abstract Base Class: ``through table`` for all ``through table``
sub classes.
taggit class name was ItemBase
"""

class Meta:
Expand Down Expand Up @@ -154,7 +155,6 @@ class TaggedItemThroughBase(ThroughTableBase):
Base class: ``through table`` for a ``Tagged Item`` model.
taggit class name was TaggedItemBase
"""

class Meta:
Expand All @@ -174,8 +174,6 @@ class GenericFKTaggedItemThroughBase(ThroughTableBase):
``GenericForeignKey``.
taggit class name was CommonGenericTaggedItemBase
"""

class Meta:
Expand Down Expand Up @@ -219,7 +217,6 @@ class IntegerFKTaggedItemThroughBase(GenericFKTaggedItemThroughBase):
``integer`` primary key.
taggit class name was GenericTaggedItemBase
"""

class Meta:
Expand All @@ -236,7 +233,6 @@ class UUIDFKTaggedItemThroughBase(GenericFKTaggedItemThroughBase):
primary key.
taggit class name was GenericUUIDTaggedItemBase
"""

class Meta:
Expand All @@ -245,23 +241,18 @@ class Meta:
object_id = models.UUIDField(verbose_name=_("object ID"), db_index=True)


class TaggedItem(IntegerFKTaggedItemThroughBase, TaggedItemThroughBase):
# Through tables ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class ModelTagIntFk(IntegerFKTaggedItemThroughBase, TaggedItemThroughBase):
"""Tagged Item Through Table using Integer Foreign Key.
Allows custom Tag models. Tagged models use a ``Integer`` primary key.
taggit class name was TaggedItem
.. note::
Changing this class name breaks the tests. Some checks made to see what
was causing the error but it requires more time.
"""

class Meta:
verbose_name = _("tagged item")
verbose_name_plural = _("tagged items")
verbose_name = _("Model Tag IntFk")
verbose_name_plural = _("Model Tags IntFk")
app_label = "tag_fields"
index_together = [["content_type", "object_id"]]
unique_together = [["content_type", "object_id", "tag"]]
4 changes: 2 additions & 2 deletions tag_fields/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.shortcuts import get_object_or_404
from django.views.generic.list import ListView

from tag_fields.models import ModelTag, TaggedItem
from tag_fields.models import ModelTag, ModelTagIntFk


def tagged_object_list(request, slug, queryset, **kwargs):
Expand All @@ -28,7 +28,7 @@ def dispatch(self, request, *args, **kwargs):
def get_queryset(self, **kwargs):
qs = super().get_queryset(**kwargs)
return qs.filter(
pk__in=TaggedItem.objects.filter(
pk__in=ModelTagIntFk.objects.filter(
tag=self.tag,
content_type=ContentType.objects.get_for_model(qs.model),
).values_list("object_id", flat=True)
Expand Down
28 changes: 14 additions & 14 deletions tests/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2 on 2023-05-08 02:07
# Generated by Django 4.2 on 2023-05-08 04:00

from django.db import migrations, models
import django.db.models.deletion
Expand All @@ -11,8 +11,8 @@ class Migration(migrations.Migration):
initial = True

dependencies = [
('tag_fields', '0001_initial'),
('contenttypes', '0002_remove_content_type_name'),
('tag_fields', '0001_initial'),
]

operations = [
Expand Down Expand Up @@ -98,15 +98,15 @@ class Migration(migrations.Migration):
name='Parent',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('tags', tag_fields.managers.ModelTagsManager(help_text='A comma-separated list of tags.', through='tag_fields.TaggedItem', to='tag_fields.ModelTag', verbose_name='Tags')),
('tags', tag_fields.managers.ModelTagsManager(help_text='A comma-separated list of tags.', through='tag_fields.ModelTagIntFk', to='tag_fields.ModelTag', verbose_name='Tags')),
],
),
migrations.CreateModel(
name='Pet',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=50)),
('tags', tag_fields.managers.ModelTagsManager(help_text='A comma-separated list of tags.', through='tag_fields.TaggedItem', to='tag_fields.ModelTag', verbose_name='Tags')),
('tags', tag_fields.managers.ModelTagsManager(help_text='A comma-separated list of tags.', through='tag_fields.ModelTagIntFk', to='tag_fields.ModelTag', verbose_name='Tags')),
],
),
migrations.CreateModel(
Expand Down Expand Up @@ -165,7 +165,7 @@ class Migration(migrations.Migration):
'indexes': [],
'constraints': [],
},
bases=('tag_fields.taggeditem',),
bases=('tag_fields.modeltagintfk',),
),
migrations.CreateModel(
name='Child',
Expand Down Expand Up @@ -304,7 +304,7 @@ class Migration(migrations.Migration):
name='TestModel',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('tags', tag_fields.managers.ModelTagsManager(help_text='A comma-separated list of tags.', through='tag_fields.TaggedItem', to='tag_fields.ModelTag', verbose_name='Tags')),
('tags', tag_fields.managers.ModelTagsManager(help_text='A comma-separated list of tags.', through='tag_fields.ModelTagIntFk', to='tag_fields.ModelTag', verbose_name='Tags')),
],
),
migrations.CreateModel(
Expand Down Expand Up @@ -393,7 +393,7 @@ class Migration(migrations.Migration):
name='Photo',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('tags', tag_fields.managers.ModelTagsManager(help_text='A comma-separated list of tags.', through='tag_fields.TaggedItem', to='tag_fields.ModelTag', verbose_name='Tags')),
('tags', tag_fields.managers.ModelTagsManager(help_text='A comma-separated list of tags.', through='tag_fields.ModelTagIntFk', to='tag_fields.ModelTag', verbose_name='Tags')),
],
options={
'abstract': False,
Expand All @@ -403,7 +403,7 @@ class Migration(migrations.Migration):
name='OrderedModel',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('tags', tag_fields.managers.ModelTagsManager(help_text='A comma-separated list of tags.', through='tag_fields.TaggedItem', to='tag_fields.ModelTag', verbose_name='Tags')),
('tags', tag_fields.managers.ModelTagsManager(help_text='A comma-separated list of tags.', through='tag_fields.ModelTagIntFk', to='tag_fields.ModelTag', verbose_name='Tags')),
],
),
migrations.CreateModel(
Expand Down Expand Up @@ -436,14 +436,14 @@ class Migration(migrations.Migration):
name='Name',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('tags', tag_fields.managers.ModelTagsManager(help_text='A comma-separated list of tags.', through='tag_fields.TaggedItem', to='tag_fields.ModelTag', verbose_name='Tags')),
('tags', tag_fields.managers.ModelTagsManager(help_text='A comma-separated list of tags.', through='tag_fields.ModelTagIntFk', to='tag_fields.ModelTag', verbose_name='Tags')),
],
),
migrations.CreateModel(
name='MultipleTagsGFK',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('tags1', tag_fields.managers.ModelTagsManager(help_text='A comma-separated list of tags.', through='tag_fields.TaggedItem', to='tag_fields.ModelTag', verbose_name='Tags')),
('tags1', tag_fields.managers.ModelTagsManager(help_text='A comma-separated list of tags.', through='tag_fields.ModelTagIntFk', to='tag_fields.ModelTag', verbose_name='Tags')),
('tags2', tag_fields.managers.ModelTagsManager(help_text='A comma-separated list of tags.', through='tests.ThroughGFK', to='tag_fields.ModelTag', verbose_name='Tags')),
],
),
Expand All @@ -461,7 +461,7 @@ class Migration(migrations.Migration):
name='Movie',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('tags', tag_fields.managers.ModelTagsManager(help_text='A comma-separated list of tags.', through='tag_fields.TaggedItem', to='tag_fields.ModelTag', verbose_name='Tags')),
('tags', tag_fields.managers.ModelTagsManager(help_text='A comma-separated list of tags.', through='tag_fields.ModelTagIntFk', to='tag_fields.ModelTag', verbose_name='Tags')),
],
options={
'abstract': False,
Expand All @@ -472,7 +472,7 @@ class Migration(migrations.Migration):
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=50)),
('tags', tag_fields.managers.ModelTagsManager(help_text='A comma-separated list of tags.', through='tag_fields.TaggedItem', to='tag_fields.ModelTag', verbose_name='Tags')),
('tags', tag_fields.managers.ModelTagsManager(help_text='A comma-separated list of tags.', through='tag_fields.ModelTagIntFk', to='tag_fields.ModelTag', verbose_name='Tags')),
],
),
migrations.AddField(
Expand Down Expand Up @@ -521,15 +521,15 @@ class Migration(migrations.Migration):
name='CustomManager',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('tags', tag_fields.managers.ModelTagsManager(help_text='A comma-separated list of tags.', through='tag_fields.TaggedItem', to='tag_fields.ModelTag', verbose_name='Tags')),
('tags', tag_fields.managers.ModelTagsManager(help_text='A comma-separated list of tags.', through='tag_fields.ModelTagIntFk', to='tag_fields.ModelTag', verbose_name='Tags')),
],
),
migrations.CreateModel(
name='BlankTagModel',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=50)),
('tags', tag_fields.managers.ModelTagsManager(blank=True, help_text='A comma-separated list of tags.', through='tag_fields.TaggedItem', to='tag_fields.ModelTag', verbose_name='Tags')),
('tags', tag_fields.managers.ModelTagsManager(blank=True, help_text='A comma-separated list of tags.', through='tag_fields.ModelTagIntFk', to='tag_fields.ModelTag', verbose_name='Tags')),
],
),
migrations.CreateModel(
Expand Down
4 changes: 2 additions & 2 deletions tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
ThroughTableBase,
ModelTag,
TagBase,
TaggedItem,
ModelTagIntFk,
TaggedItemThroughBase,
)

Expand Down Expand Up @@ -344,7 +344,7 @@ def slugify(self, tag, i=None):
return slug


class ArticleTaggedItem(TaggedItem):
class ArticleTaggedItem(ModelTagIntFk):
class Meta:
proxy = True

Expand Down
4 changes: 2 additions & 2 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from django.test.utils import override_settings

from tag_fields.managers import ModelTagsManager, _TaggableManager
from tag_fields.models import ModelTag, TaggedItem
from tag_fields.models import ModelTag, ModelTagIntFk
from tag_fields.utils import edit_string_for_tags, parse_tags
from tag_fields.views import tagged_object_list

Expand Down Expand Up @@ -174,7 +174,7 @@ class TaggableManagerTestCase(BaseTaggingTestCase):
multi_inheritance_food_model = MultiInheritanceFood
pet_model = Pet
housepet_model = HousePet
taggeditem_model = TaggedItem
taggeditem_model = ModelTagIntFk
tag_model = ModelTag

def setUp(self):
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ deps =
djangorestframework
commands =
coverage run -m django test --settings=tests.settings {posargs}
; coverage run -m django test --verbosity=2 --settings=tests.settings {posargs}
coverage report
coverage xml
ignore_outcome =
Expand Down

0 comments on commit af4f531

Please sign in to comment.