django-taggit

django/taggit - unhashable type: 'list'

送分小仙女□ 提交于 2019-12-04 18:45:40
I'm using django-taggit (see here ). This is what I have: forms.py from taggit.forms import * class MyForm(forms.Form): title = forms.CharField() my_tags = TagField(max_length=800, widget=forms.TextInput(attrs={'class':'myTags'})) views.py if 'submit_button' in request.POST: form = MyForm(request.POST) if form.is_valid(): cd = form.cleaned_data f_title = cd['title'] f_my_tags = cd['my_tags'] p = MyData.objects.create(title=f_title) p.tags.add(f_my_tags) p.save() mytemplate.html {{ form.my_tags.errors }} {{ form.my_tags }} Not sure why I get unhashable type: 'list' when I use p.tags.add(f_my

How can I limit django-taggit to accept only lowercase words?

六月ゝ 毕业季﹏ 提交于 2019-12-04 09:39:05
I'm using django-taggit. I'd like to have all tags in lowercase, also set a range for tag numbers (say between 1 and 5, just like stackoverflow). Is there any way to do it easily with django-taggit? Thanks! You might want to check out this branch. https://github.com/shacker/django-taggit it has a FORCE_LOWERCASE setting. It's pretty easy to do with django-taggit. Subclass TagBase and enforce the lowercase constraint in the save method. The rest is boiler point so TaggableManager can use your subclass. class LowerCaseTag(TagBase): def save(self, *args, **kwargs): self.name = self.name.lower()

Using Django-taggit with django-rest-framework, i'm not able to save my tags

江枫思渺然 提交于 2019-12-03 17:38:59
问题 I'm trying to figure it out why when i submit my form, my tags are not saved in my db. Pretty new with the django-rest-framework and Django-taggit too, i think i'm doing something wrong :) First, before making my API with the rest-framework, i was using a generic view (CreateView and UpdateView) to register/validate my event. It was working fine but i decided to go further and try to build an API since i'm using Angularjs now. Now my model event is created but without my tag and i have some

Django-taggit prefetch_related

落爺英雄遲暮 提交于 2019-12-03 13:33:26
I'm building a basic time logging app right now and I have a todo model that uses django-taggit. My Todo model looks like this: class Todo(models.Model): project = models.ForeignKey(Project) description = models.CharField(max_length=300) is_done = models.BooleanField(default=False) billable = models.BooleanField(default=True) date_completed = models.DateTimeField(blank=True, null=True) completed_by = models.ForeignKey(User, blank=True, null=True) tags = TaggableManager() def __unicode__(self): return self.description I'm trying to get a list of unique tags for all the Todos in a project and I

How do I create list and detail views for django-taggit?

柔情痞子 提交于 2019-12-03 01:36:50
I have a fairly simple model that uses Django Taggit for tagging. Everything works great, but now I'd like to expand some functionality and I'm a little confused. What I want is two views. One that shows all my tags in the system. One that shows all the content from my app with a specific tag. What makes sense to me is to do the following for each view. in views.py for myapp All Tags from myapp.models import App from taggit.models import Tag class TagList(ListView): """ Get all the tags in the db """ queryset = Tag.objects.all() template_name = "myapp/TagList.html" paginate_by = 10 All content

filter tags of django-taggit in Django's Queryset

匆匆过客 提交于 2019-12-02 12:45:50
Having the following models: class Post(models.Model): title = models.CharField(max_length=250) tags = TaggableManager() and the data are: **post.title** **post.tags** Django By Example python,django,web Who was Django Reinhardt python,django, Test-Driven Development with Python python,web Python for Data Analysis python,data Learning Python python Programming Python python Automate the Boring Stuff with Python python I try to code below >>> alist=Post.objects.filter(tags__name__in=["data","python"]) >>> for i in alist.annotate(sam_tags=Count('tags')): ... print("\n---",i) ... print("tags of

Django-Taggit in Edit Form

我们两清 提交于 2019-11-30 15:42:17
This is a Model Class class ModelName(models.Model): (...) pasta = TaggableManager(verbose_name=u'Pasta') and a form template (normal :P ) {{form.as_p}} I'd like to leave everything very clean and usefull. But result is a list of TaggedItem Object :( : [<TaggedItem: id: 2 tagged with general >, <TaggedItem: id: 3 tagged with outer >] Instead of something like general, outer How do it fashionably in Django? Arthur Alvim Give a look at the code in: https://github.com/alex/django-taggit/blob/master/taggit/forms.py . You will find the widget used to render the tags. You can use it to render them

django - django-taggit form

随声附和 提交于 2019-11-30 05:18:34
I would like to use django-taggit ( click here ). The documentation ( click here ) talks about using ModelForm to generate the form but I have already my form that I would like to use. Let's say if I have something like this: forms.py class MyForm(forms.Form): ...... tags = forms.CharField(max_length=200, widget=forms.Textarea) how do I save the the tags coming from the tags field? What goes in my views.py ? A real example would be truly appreciated. I'm not too familiar with the django taggit app, but it looks like if you want to use the same field and widget setup the app uses, you can

Django-Taggit in Edit Form

帅比萌擦擦* 提交于 2019-11-29 23:04:29
问题 This is a Model Class class ModelName(models.Model): (...) pasta = TaggableManager(verbose_name=u'Pasta') and a form template (normal :P ) {{form.as_p}} I'd like to leave everything very clean and usefull. But result is a list of TaggedItem Object :( : [<TaggedItem: id: 2 tagged with general >, <TaggedItem: id: 3 tagged with outer >] Instead of something like general, outer How do it fashionably in Django? 回答1: Give a look at the code in: https://github.com/alex/django-taggit/blob/master

Django __in lowercase

烈酒焚心 提交于 2019-11-29 12:25:18
I'm using django-taggit , which handles the attachment of tags to arbitrary content types. I imported a large tag list, which contains many uppercase words, as well as lowercase words. Now, I' trying to get objects of another class containing a set of tags, but I want to compare case insensitively. When I do this: Media.objects.filter(tags__name__in=['tag1', 'tag2']) objects containing e.g. the tag "Tag1" are not found, only those ones with "tag1" or "tag2". Is there any possibility in the django orm to do something like: Media.objects.filter(tags__name__iin=['tag1', 'tag2']) that acts like