question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Trying to implement user owned tags in django-taggit for specific objects

See original GitHub issue

I am trying to implement a Video model in Django 1.11 which are tagged by both global tags (which are added by the admin when the video is first uploaded) which are able to be viewed by everyone accessing, and user specific tags (added by users per video) which are specific to the user logged in.

Currently, the model looks something like this:

class Video(models.Model):
    video_name = models.CharField(max_length=50)
    video_pub_date = models.DateTimeField('date published')
    video_file = models.FileField()
    video_thumbnail = models.ImageField(null=True, blank=True)
    global_tags = TaggableManager()
    video_views = models.IntegerField(default=0)

User model is just using from django.contrib.auth.models import User but not explicitly defined in my models.py file

However, in addition to global_tags, I need a way to have private tags (user specific). This answer shows how to get tags for objects that are associated with a specific user, but this is not what I want since the object themselves (in my case Video), is not owned by anyone in particular, but the tags themselves are to be owned by specific user.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
olleugracommented, Apr 14, 2021

My solution was to adapt django taggit as a local app. then I modified the TagBase to remove the uniqueness for ‘name’ and ‘slug’ fields. I also added a user foreignkey.

class TagBase(models.Model):`
    user = models.ForeignKey(User, null=True, on_delete=models.CASCADE,related_name='tagbaseuser')
    name = models.CharField(verbose_name=_("Name"), unique=False, max_length=100)
    slug = models.SlugField(verbose_name=_("Slug"), unique=False, max_length=100)
1reaction
gilgameshskytroopercommented, Dec 10, 2019

This feels a bit backstabby to Django, but for the past 2 years, I’ve used idomatic Go to write my backends [for both work and personal projects] (rolling my own native SQL queries using the Go std lib without ORM’s etc.) and I’ve never looked back.

Basically in my experience, once you write your Django app, you still have to put in a significant effort in optimizing your backend to maximize cores by using a WSGI, managing dependency during production execution. However, with Go, the default go build command builds a production ready fully non-threaded backend executable that you can just start running, and reverse proxy requests to (which is far easier to manage during production execution).

At the same time, because of the strong support for most backend related logic in the standard library, you can always r.y.o model classes no problem

I would encourage anyone having trouble Django or Rails to check out Go.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Customizing taggit — django-taggit 1.3.0 documentation
Using a Custom Tag or Through Model¶. By default django-taggit uses a “through model” with a GenericForeignKey on it, that has another ForeignKey...
Read more >
Getting a specific tag object using django-taggit - Stack Overflow
@Aamir Adnan I just want the current tag, not all tags associated with the object. – azio. Nov 30, 2012 at 20:34.
Read more >
django-taggit - Read the Docs
Note: If you want django-taggit to be CASE-INSENSITIVE when looking ... sets the object's tags to those specified, removing only the missing ...
Read more >
Django: Tagging — Python 401 2.1 documentation
Django -Taggit is an independent app, so it has its own migrations to apply ... the TaggableManager from taggit.managers , then use that...
Read more >
How to add tags to your models in Django - DEV Community ‍ ‍
A tag is more specific and addresses items you discuss in a particular blog ... from django.db import models from taggit.managers import ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found