Python 向模型添加多个标记
我有以下型号:Python 向模型添加多个标记,python,django,django-taggit,Python,Django,Django Taggit,我有以下型号: class Investor(Profile): ROLE = ( ('AN', 'Angel Investor'), ('VC', 'Venture Capital'), ('SC', 'Seed Capital') ) role = models.CharField(max_length=2, default='AN', choices=ROLE) min_inv = models.DecimalField( default=0, max_di
class Investor(Profile):
ROLE = (
('AN', 'Angel Investor'),
('VC', 'Venture Capital'),
('SC', 'Seed Capital')
)
role = models.CharField(max_length=2, default='AN', choices=ROLE)
min_inv = models.DecimalField(
default=0, max_digits=20, decimal_places=2,
verbose_name='Minimum Investments per year')
max_inv = models.DecimalField(
default=0, max_digits=20, decimal_places=2,
verbose_name='Maximum investments per year')
no_startups = models.IntegerField(
default=0, verbose_name='Number of investments per year')
rating_sum = models.FloatField(default=0)
no_raters = models.IntegerField(default=0)
我想在此模型中添加多个标记。
-类别
-舞台
-资助
我希望投资者被分配到多个类别、阶段和资金。
因此,投资者可以绑定到多个类别
多阶段
以及多种资金类型
我如何编辑模型才能做到这一点?您能为连接的模型添加关系吗
class Investor(Profile):
ROLE = (
('AN', 'Angel Investor'),
('VC', 'Venture Capital'),
('SC', 'Seed Capital')
)
role = models.CharField(max_length=2, default='AN', choices=ROLE)
min_inv = models.DecimalField(
default=0, max_digits=20, decimal_places=2,
verbose_name='Minimum Investments per year')
max_inv = models.DecimalField(
default=0, max_digits=20, decimal_places=2,
verbose_name='Maximum investments per year')
no_startups = models.IntegerField(
default=0, verbose_name='Number of investments per year')
rating_sum = models.FloatField(default=0)
no_raters = models.IntegerField(default=0)
categories = models.ManyToMany(Category)
stages = models.ManyToMany(Stage)
fundings = models.ManyToMany(Funding)
然后,使用manytomen可以指定阶段
investor = Investor.objects.all()[0]
investor.categories.add(category_instance_one, category_instance_two)
investor.categories.all() # retrieves all categories that this investor has