Commit de544253 by Florian Apolloner

Cleaned up the TaggableManager constructor.

parent 62525c27
from __future__ import unicode_literals from __future__ import unicode_literals
import django
from django.contrib.contenttypes.generic import GenericRelation from django.contrib.contenttypes.generic import GenericRelation
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from django.db import models from django.db import models
from django.db.models.fields import Field
from django.db.models.fields.related import ManyToManyRel, RelatedField, add_lazy_relation from django.db.models.fields.related import ManyToManyRel, RelatedField, add_lazy_relation
from django.db.models.related import RelatedObject from django.db.models.related import RelatedObject
from django.utils.text import capfirst from django.utils.text import capfirst
...@@ -24,28 +24,12 @@ class TaggableRel(ManyToManyRel): ...@@ -24,28 +24,12 @@ class TaggableRel(ManyToManyRel):
self.through = None self.through = None
class TaggableManager(RelatedField): class TaggableManager(RelatedField, Field):
def __init__(self, verbose_name=_("Tags"), def __init__(self, verbose_name=_("Tags"),
help_text=_("A comma-separated list of tags."), through=None, blank=False): help_text=_("A comma-separated list of tags."), through=None, blank=False):
Field.__init__(self, verbose_name=verbose_name, help_text=help_text, blank=blank)
self.through = through or TaggedItem self.through = through or TaggedItem
self.rel = TaggableRel() self.rel = TaggableRel()
self.verbose_name = verbose_name
self.help_text = help_text
self.blank = blank
self.editable = True
self.creates_table = False
self.db_column = None
self.serialize = False
self.null = True
self.primary_key = False
self._choices = []
self._unique = False
# Remove once we drop 1.5 support.
if django.VERSION < (1, 6):
self.choices = None
self.unique = False
self.creation_counter = models.Field.creation_counter
models.Field.creation_counter += 1
def __get__(self, instance, model): def __get__(self, instance, model):
if instance is not None and instance.pk is None: if instance is not None and instance.pk is None:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment