CODE:
class Basemodel(models.Model):
set = models.ManyToManyField(User, related_name="setset_set", symmetrical=False, through="Follow")
class Meta :
abstract = True
class Post_1(Basemodel):
post1 = models.CharField(max_length=50)
class Post_2(Basemodel):
post2 = models.CharField(max_length=50)
class Follow(models.Model):
follower = models.ForeignKey(User, related_name="who_is_allowing",)
followee = models.ForeignKey(Basemodel, related_name="who_is_allowed",)
created_at = models.DateTimeField(auto_now_add=True,)
updated_at = models.DateTimeField(auto_now=True,)
def __str__(self):
return "%s follows %s at %s" %(self.follower, self.followee, self.updated_at)
在那些代码中,我想在抽象类中创建一个ManyToManyField。
所以我想让用户可以关注Post_1或Post_2,无论是哪种帖子。
此外,我想检查一下Follow Class
的使用情况,Basemodel
- set = models.ManyToManyField
- through
kwargs < / p>
有没有办法让它成为可能?