threadparticipant.py 1014 B

1234567891011121314151617181920212223242526272829303132
  1. from django.db import models
  2. from misago.conf import settings
  3. class ThreadParticipantManager(models.Manager):
  4. def remove_participant(self, thread, user):
  5. ThreadParticipant.objects.filter(thread=thread, user=user).delete()
  6. def set_owner(self, thread, user):
  7. thread_owner = ThreadParticipant.objects.filter(
  8. thread=thread, is_owner=True)
  9. thread_owner.update(is_owner=False)
  10. self.remove_participant(thread, user)
  11. ThreadParticipant.objects.create(
  12. thread=thread,
  13. user=user,
  14. is_owner=True)
  15. def add_participant(self, thread, user, is_owner=False):
  16. ThreadParticipant.objects.create(
  17. thread=thread,
  18. user=user,
  19. is_owner=is_owner)
  20. class ThreadParticipant(models.Model):
  21. thread = models.ForeignKey('misago_threads.Thread')
  22. user = models.ForeignKey(settings.AUTH_USER_MODEL)
  23. is_owner = models.BooleanField(default=False)
  24. objects = ThreadParticipantManager()