Questions tagged «django-custom-manager»

3
Django动态模型字段
我正在开发一个多租户应用程序,其中一些用户可以定义自己的数据字段(通过管理员)以收集表单中的其他数据并报告数据。后一点使得JSONField不是一个很好的选择,所以我有以下解决方案: class CustomDataField(models.Model): """ Abstract specification for arbitrary data fields. Not used for holding data itself, but metadata about the fields. """ site = models.ForeignKey(Site, default=settings.SITE_ID) name = models.CharField(max_length=64) class Meta: abstract = True class CustomDataValue(models.Model): """ Abstract specification for arbitrary data. """ value = models.CharField(max_length=1024) class Meta: abstract = …

5
在Django中的自定义管理器中捕获DidsNotExist异常
我有一个Django模型的自定义管理器。我似乎无法在此处捕获DidNotExist异常。我知道如何在模型中执行此操作,但在这里不起作用: class TaskManager(models.Manager): def task_depend_tree(self, *args, **kwargs): if "id" in kwargs: try: task = self.get(id=kwargs["id"]) except DoesNotExist: raise Http404 Get_object_or_404也不起作用。怎么了
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.