Python django taggit定制&x27;标签';model和request.user
我需要跟踪标记的创建时间和创建人,因此使用django taggit创建了一个自定义标记模型,如Python django taggit定制&x27;标签';model和request.user,python,django,django-taggit,django-autocomplete-light,Python,Django,Django Taggit,Django Autocomplete Light,我需要跟踪标记的创建时间和创建人,因此使用django taggit创建了一个自定义标记模型,如 class Topics(TagBase): featured = models.BooleanField(_('Featured'), default=False) created = models.DateTimeField(_('Creation date'), auto_now_add=True, editable=False) created_by = model
class Topics(TagBase):
featured = models.BooleanField(_('Featured'), default=False)
created = models.DateTimeField(_('Creation date'), auto_now_add=True, editable=False)
created_by = models.ForeignKey(User, related_name="topic_created_by")
class ArticleTopic(ItemBase):
content_object = models.ForeignKey('Article')
tag = models.ForeignKey(Topics, related_name="topic_items")
class Article(models.Model):
title = models.CharField(_('Title'), max_length=255)
excerpt = models.TextField(_('Excerpt'))
content = models.TextField(_('Content'), blank=True)
topics = TaggableManager(through=ArticleTopic)
created = models.DateTimeField(_('Creation date'), auto_now_add=True, editable=False)
created_by = models.ForeignKey(User, related_name="article_created_by")
我正在使用django autocomplete light为管理员中的主题创建一个autocomplete字段,并在保存文章表单时键入一个新主题
虽然我知道我可以在管理表单中获取request.user并通过save_model方法传递它-这就是我为文章模型所做的-但我不知道如何为主题模型这样做
提前感谢我遇到了类似的问题,并用django taggit添加了此功能: 为自定义直通或标记模型添加属性,如下所示:
article.topics.add('topic1', 'topic2', created_by=request.user)
也许是干净的标签?@jpic不是真的。这是在保存文章之前,主题需要文章实例来生成关系。我必须在其中重新创建taggit的TaggableManager()功能——假设这是可能的。这似乎正是我所需要的。谢谢然而,我不能让它工作。错误是
companys.companytype:“topics”是通过CompanyTopic模型手动定义的m2m关系,它没有主题和companytype的外键,我认为这与attname
有关,但我不知道在哪里设置它。如果这有助于它工作,我正在使用GenericTaggedItemBase
。切换回稳定版本并包含您的提交。无法说明开发版本中发生了哪些变化,这些变化对我的代码不是很好,而是将来需要处理的问题。我对django taggit有问题,你能帮助我吗?