Skip to content

Instantly share code, notes, and snippets.

@mentix02
Last active August 27, 2020 15:22
Show Gist options
  • Save mentix02/621b11f234576fb6f1fe328aa253a6f7 to your computer and use it in GitHub Desktop.
Save mentix02/621b11f234576fb6f1fe328aa253a6f7 to your computer and use it in GitHub Desktop.
from django.db import models
from typing import List, Tuple
class FollowRequest(models.Model):
requester = models.ForeignKey('user.User', on_delete=models.CASCADE)
to_follow = models.ForeignKey(
'user.User', on_delete=models.CASCADE, related_name='requests'
)
def accept(self) -> None:
self.requester.follow(self.to_follow, force=True)
self.delete()
def reject(self) -> None:
self.delete()
def __str__(self) -> str:
return f'{self.requester} -> {self.to_follow}'
class Meta:
indexes: List[models.Index] = [
models.Index(fields=('to_follow',)),
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment