django-taggit

Django-taggit prefetch_related

有些话、适合烂在心里 提交于 2019-12-21 04:28:07
问题 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)

Optimize django query to pull foreign key and django-taggit relationship

旧街凉风 提交于 2019-12-19 04:06:10
问题 I have a todo model defined below: class Action(models.Model): name = models.CharField("Action Name", max_length=200, unique = True) complete = models.BooleanField(default=False, verbose_name="Complete?") reoccurance = models.ForeignKey(Reoccurance, blank=True, null=True, verbose_name="Reoccurance") notes = models.TextField("Notes", blank=True) tags = TaggableManager() class Reoccurance(models.Model): label = models.CharField("Label", max_length=50, unique = True) days = models.IntegerField(

Tag detail page with Django-taggit

巧了我就是萌 提交于 2019-12-12 06:23:58
问题 Im trying to create pages for tags on my django blog. I already have a simple index page which displays a list of all used tags, now I want to have individual pages for each tag and on that page I will display all posts marked with that tag. The url structure for these tag detail pages will be like this localhost/tag/my-tag-here I already have django-taggit installed and added some tags and I have them displaying fine on post detail pages and the tag index page mentioned above but Im getting

Customising tags in Django to filter posts in Post model

拈花ヽ惹草 提交于 2019-12-12 03:59:49
问题 Quick question - I'm not sure what would be the correct way to handle this. Essentially I wish to define a custom tag which handles some logic then returns all posts of model Post which has the is_featured field set to True. I have tried a number of avenues to get this working, but none have worked. My last coherant "guess" was the following: templatetags/blog_tags.py: @register.inclusion_tag('blog/post/featured_posts.html') def show_featured_posts(count=4): """Return 4 of the most recent

Exclude some Posts from count of tags

陌路散爱 提交于 2019-12-11 15:54:10
问题 I'm using django-taggit to manage my tag. I want to include a list of used tags with the indication of how many times each of them has been used. To do so I'm using taggit_templatetags2 but I can avoid. My models.py : from taggit.managers import TaggableManager class Post(models.Model): ... tags = TaggableManager(blank=True) My template.html : {% load taggit_templatetags2_tags %} {% get_taglist as tags for 'blog.post' %} {% for tag in tags %} {% if tag.slug != 'draft' and tag.slug != 'retired

How to filter django-taggit top tags

蹲街弑〆低调 提交于 2019-12-11 02:56:03
问题 Suppose you have a database with User objects running behind a Djano app and you want to use django-taggit to tag User objects so you can retrieve subgroups using some convenient filtering. Additionally you have a Dashboard where you want to display interesting statistics about used tags to glean some information about the subgroups that exists within your Users. How would you access and display information about the top X tags used within the Django app? How would you access only the top X

make case-insensitive tags with django-taggit

怎甘沉沦 提交于 2019-12-07 01:45:19
问题 I added tags = TaggableManager(blank=True) to my models, but I want my tags to be case-insensitive. I saw some snippets of work arounds for this and wanted to ask if there is an easy way to do it? If I have to override some methods from the TaggableManager, please advise how can I do that? Thanks in advance, Arshavski Alexander. 回答1: I have used this snippet for a similar issue. A copy of the code (reprinted for posterity): from django.db.models import Manager from django.db.models.query

django-taggit: make the tags not required in the admin

只愿长相守 提交于 2019-12-06 17:12:13
问题 I've started using django-taggit and it seems to fit the bill. But for me there is still an issue with the admin site: I included the tags attribute in the ModelAdmin like this: class MyModel(db.models.Model): name = models.CharField(max_length=200) tags = TaggableManager() class MyModelAdmin(admin.ModelAdmin): fieldsets = ( (None, { 'fields': ('name', 'tags') }), ) And everything goes as expected. But when I edit a model in the admin, I get an error, if the TagField is empty. The form seems

django/taggit - unhashable type: 'list'

此生再无相见时 提交于 2019-12-06 15:02:37
问题 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

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

為{幸葍}努か 提交于 2019-12-06 04:53:15
问题 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! 回答1: You might want to check out this branch. https://github.com/shacker/django-taggit it has a FORCE_LOWERCASE setting. 回答2: 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