Get it from self.topic
:
top = Video.objects.filter(topic=self.topic).order_by('-sequence')[0]
You can also use latest()
instead of sorting and taking [0]
out of the queryset:
top = Video.objects.filter(topic=self.topic).latest('sequence')
In this case latest()
would get the single Video
model instance that has the maximum sequence
value for the particular topic.
See also: Overriding predefined model methods.