python - Django getting objects from a mixin -
i have small model method i'm using previous , next object relative current object. looks this:
class article ... def get_prev_next(self): articles = list(article.objects.all()) = articles.index(self) try: p = articles[i - 1] except indexerror: p = none try: n = articles[i + 1] except indexerror: n = none return {'prev': p, 'next': n}
it works, , may inefficient, want use in different model.
i'd make mixin, can't figure out how original model class name can run model.objects.all() , list.
i have far:
class prevnextmixin(object): objects = list(???.objects.all()) = objects.index(self) ...
a mixin still class. code still needs go method. method self
argument now.
class prevnextmixin(object): def get_prev_next(self): objects = list(self.__class__.objects.all())
Comments
Post a Comment