私は次のモデルのセットを持っています(わかりやすくするために省略しています):
最初のセット:
class Web(Link):
ideas = models.ManyToManyField(Idea, blank=True, null=True)
precedents = models.ManyToManyField(Precedent, blank=True, null=True)
categories = GenericRelation(CategoryItem)
@permalink
def get_absolute_url(self):
return ('resources-link-detail', [str(self.slug)])
これは次の子です:
class Link(models.Model):
title = models.CharField(max_length=250)
description = models.TextField(blank=True)
website = models.URLField(unique=True)
slug = models.SlugField(unique_for_date='pub_date')
...
@permalink
def get_absolute_url(self):
return ('link-detail', [str(self.slug)])
2セット目
class ResourceOrganization(Organization):
ideas = models.ManyToManyField(Idea, blank=True, null=True)
precedents = models.ManyToManyField(Precedent, blank=True, null=True)
categories = GenericRelation(CategoryItem)
@permalink
def get_absolute_url(self):
return ('resources-org-detail', [str(self.slug)])
これは次の子です:
class Organization(Contact):
name = models.CharField(max_length=100)
org_type = models.PositiveSmallIntegerField(choices=ORG_CHOICES)
...
@permalink
def get_absolute_url(self):
return ('org-detail', [str(self.slug)])
これは次の子です:
class Contact(models.Model):
description = models.TextField(blank=True, null=True)
address_line1 = models.CharField(max_length=250, blank=True)
address_line2 = models.CharField(max_length=250, blank=True)
slug = models.SlugField(unique=True)
...
class Meta:
abstract = True
「ResourceOrganization」モデルは get_absolute_url メソッドを適切にオーバーライドし、「categories」ジェネリック リレーションを追加しています。
「Web」モデルはそうではありません。
私はその理由を理解するのに途方に暮れています。洞察をいただければ幸いです。
PS この機能を実装するためのより良い方法があったかもしれないことを認識していますが、リファクタリングが可能になり、機能させたいと思うまで、しばらくの間それを使い続けています。
ありがとう。