mirror of https://github.com/zulip/zulip.git
mute user: Add model and makemigrations.
This commit adds a new database table to support muting users, and generates a migration file for the same.
This commit is contained in:
parent
c6dfe7bf40
commit
89f6139505
|
@ -0,0 +1,47 @@
|
|||
# Generated by Django 3.1.5 on 2021-02-12 12:10
|
||||
|
||||
import django.db.models.deletion
|
||||
import django.utils.timezone
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("zerver", "0313_finish_is_user_active_migration"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name="MutedUser",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.AutoField(
|
||||
auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
|
||||
),
|
||||
),
|
||||
("date_muted", models.DateTimeField(default=django.utils.timezone.now)),
|
||||
(
|
||||
"muted_user_profile",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
related_name="+",
|
||||
to=settings.AUTH_USER_MODEL,
|
||||
),
|
||||
),
|
||||
(
|
||||
"user_profile",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
related_name="+",
|
||||
to=settings.AUTH_USER_MODEL,
|
||||
),
|
||||
),
|
||||
],
|
||||
options={
|
||||
"unique_together": {("user_profile", "muted_user_profile")},
|
||||
},
|
||||
),
|
||||
]
|
|
@ -1845,6 +1845,18 @@ class MutedTopic(models.Model):
|
|||
return f"<MutedTopic: ({self.user_profile.email}, {self.stream.name}, {self.topic_name}, {self.date_muted})>"
|
||||
|
||||
|
||||
class MutedUser(models.Model):
|
||||
user_profile = models.ForeignKey(UserProfile, related_name="+", on_delete=CASCADE)
|
||||
muted_user_profile = models.ForeignKey(UserProfile, related_name="+", on_delete=CASCADE)
|
||||
date_muted: datetime.datetime = models.DateTimeField(default=timezone_now)
|
||||
|
||||
class Meta:
|
||||
unique_together = ("user_profile", "muted_user_profile")
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"<MutedUser: {self.user_profile.email} -> {self.muted_user_profile.email}>"
|
||||
|
||||
|
||||
class Client(models.Model):
|
||||
id: int = models.AutoField(auto_created=True, primary_key=True, verbose_name="ID")
|
||||
name: str = models.CharField(max_length=30, db_index=True, unique=True)
|
||||
|
|
Loading…
Reference in New Issue