经理不可用;游戏是抽象的

时间:2019-07-09 09:59:44

标签: django django-models

当我尝试保存时,出现此错误。 Manager isn't available; Game is abstract 我尝试了一些发现的方法,但是没有用;像objects = models.Manager()

当我删除objects = models.Manager()时 我收到此错误type object 'Game' has no attribute 'objects'

我的模型。py

class Game(models.Model):
    name=models.CharField(max_length=255,blank=True,null=True)
    slug=models.SlugField(unique=True,max_length=255)
    match=models.ManyToManyField(Match)

    objects=models.Manager()


    def get_unique_slug(self):
        slug=slugify(self.name.replace('ı','i'))
        unique_slug=slug
        counter=1
        while Game.objects.filter(slug=unique_slug).exists():
            unique_slug='{}-{}'.format(slug,counter)
            counter+=1
        return slug


    def save(self,*args,**kwargs):
        self.slug=self.get_unique_slug()
        return super(Game,self).save(*args,**kwargs)


    class Meta:
        abstract = True


class LeagueOfLegendsGame(Game):
    team1player=models.ManyToManyField(Player,related_name='team1player')
    team2player=models.ManyToManyField(Player,related_name='team2player')

0 个答案:

没有答案