Django proxy model and ForeignKey

前端 未结 6 2087
温柔的废话
温柔的废话 2020-12-05 01:28

How to make entry.category to be instance of CategoryProxy? See code for details:

class Category(models.Model): pass

class Entry(models.Model):
    category         


        
6条回答
  •  一整个雨季
    2020-12-05 01:52

    Define a property category on EntryProxy that looks up the CategoryProxy by its id:

    class EntryProxy(Entry):
        @property
        def category(self):
            cid = super(EntryProxy, self).category.id
            return CategoryProxy.objects.get(id=cid)
    
        class Meta:
            proxy = True
    

提交回复
热议问题