I have a question about the use of django-taggit. I have a UserProfile (which I attach using AUTH_PROFILE_MODULE in the settings file) in which I store a set of skills for tutors such as: , , etc. Then, when someone wants to request a tutoring session, they can write a description of what they want and place tags for their request. (For example, I want a tutor skilled in calculus and physics). If I let the users of the site choose their own tags, then I worry that we could end up with "tag hell" where we have tags such as , , etc. So, I want to tag skills, but only from a table that I populate in the admin as we add people. That avoids the diffusion problem (similar to how stackoverflow works).
Here is some trial Code:
from django.db import models </br>
from django.contrib.auth.models import User
from taggit.managers import TaggableManager
class BaseUser(models.Model):
class Meta:
abstract=True
first_name=models.CharField(max_length=100)
skills=TaggableManager()
class UserProfile(BaseUser):
user=models.ForeignKey(User,unique=True)
class TutoringSession(models.Model):
title=models.CharField(max_length=100,blank=False)
slug=models.SlugField(max_length=250,unique=True,blank=False,editable=False)
tags=TaggableManager()
Or, is it bette开发者_StackOverflowr to use a Tags class:
class Tags:
name=models.CharField(max_length=100, blank=False, unique=True)
and set up a ManyToMany relation to it in both TutoringSession and UserProfile?
Thanks!
I should note that this is related to question: What benefit does Django-Taggit provide over a simple ManyToManyField() implementation of tagging?
except that in that example, we might want to limit the set of allowed answers to red and purple (that we've defined in a table because it might change)
So you want a set of predefined tags and the Users as well as the TutoringSessions should relate to one or more of these tags. Thats (as far as I can see) what m2m-fields are made for. Maybe taggit has some usability advantages (I'm not familiar with it), but the functionality described here can be achieved with simple m2m-fields.
精彩评论