-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from MrHamedi/chat_models
Chat models
- Loading branch information
Showing
16 changed files
with
224 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"editor.defaultFormatter": null, | ||
"editor.formatOnSave": true, | ||
"python.formatting.provider": "black", | ||
"python.linting.enabled": true, | ||
"python.linting.lintOnSave": true, | ||
"python.linting.flake8Enabled": true, | ||
"python.linting.flake8Args": [ | ||
"--max-line-length", | ||
"119", | ||
], | ||
"[python]": { | ||
"editor.codeActionsOnSave": { | ||
"source.organizeImports": true | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import time | ||
|
||
from django.db import connections | ||
from django.db.utils import OperationalError | ||
from django.core.management.base import BaseCommand | ||
|
||
|
||
class Command(BaseCommand): | ||
""" | ||
Wait until the database is available | ||
""" | ||
def handle(self, *args ,**options): | ||
db_con=None | ||
while not db_con: | ||
try: | ||
db_con=connections["default"] | ||
except OperationalError: | ||
self.stdout.write("waiting for database connection...") | ||
time.sleep(1) | ||
|
||
self.stdout.write("database available!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django.contrib import admin | ||
|
||
from .models import Server, Channel, Category | ||
# Register your models here. | ||
admin.register(Channel) | ||
admin.register(Category) | ||
admin.register(Server) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class ServerConfig(AppConfig): | ||
default_auto_field = 'django.db.models.BigAutoField' | ||
name = 'server' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Generated by Django 4.2.7 on 2023-11-23 19:59 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Category', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=300, verbose_name='عنوان')), | ||
('description', models.TextField(verbose_name='توضیحات')), | ||
], | ||
options={ | ||
'verbose_name': 'نوع', | ||
'verbose_name_plural': 'انواع', | ||
'ordering': ('name',), | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='Server', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=300, verbose_name='عنوان')), | ||
('description', models.TextField(verbose_name='توضیحات')), | ||
('category', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='server.category', verbose_name='نوع')), | ||
('owner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='مالک')), | ||
], | ||
options={ | ||
'verbose_name': 'سرور', | ||
'verbose_name_plural': 'سرور ها', | ||
'ordering': ('name',), | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='Channel', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=300, verbose_name='عنوان')), | ||
('topic', models.CharField(max_length=300, verbose_name='موضوع')), | ||
('owner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='channel_owner', to=settings.AUTH_USER_MODEL, verbose_name='مالک')), | ||
('server', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='channel_server', to='server.server', verbose_name='سرور')), | ||
], | ||
options={ | ||
'verbose_name': 'کانال', | ||
'verbose_name_plural': 'کانال ها', | ||
'ordering': ('name',), | ||
}, | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from django.db import models | ||
from django.contrib.auth import get_user_model | ||
|
||
|
||
class Category(models.Model): | ||
name = models.CharField(max_length=300, verbose_name="عنوان") | ||
description = models.TextField(verbose_name="توضیحات") | ||
|
||
class Meta: | ||
ordering = ('name',) | ||
verbose_name = "نوع" | ||
verbose_name_plural = "انواع" | ||
|
||
def __str__(self): | ||
return self.name | ||
|
||
|
||
class Server(models.Model): | ||
name = models.CharField(max_length=300, verbose_name="عنوان") | ||
owner = models.ForeignKey(get_user_model(), on_delete=models.CASCADE, | ||
verbose_name="مالک") | ||
description = models.TextField(verbose_name="توضیحات") | ||
category = models.ForeignKey(Category, on_delete=models.CASCADE, | ||
verbose_name="نوع") | ||
|
||
class Meta: | ||
ordering = ('name',) | ||
verbose_name = "سرور" | ||
verbose_name_plural = "سرور ها" | ||
|
||
def __str__(self): | ||
return self.name | ||
|
||
|
||
class Channel(models.Model): | ||
name = models.CharField(max_length=300, verbose_name="عنوان") | ||
topic = models.CharField(max_length=300, verbose_name="موضوع") | ||
owner = models.ForeignKey(get_user_model(), on_delete=models.CASCADE, | ||
related_name="channel_owner", verbose_name="مالک") | ||
server = models.ForeignKey(Server, on_delete=models.CASCADE, verbose_name="سرور", | ||
related_name="channel_server") | ||
|
||
class Meta: | ||
ordering = ("name",) | ||
verbose_name = "کانال" | ||
verbose_name_plural = "کانال ها" | ||
|
||
def save(self, *args, **kwargs): | ||
self.name = self.name.lower() | ||
|
||
def __str__(self): | ||
return self.name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from django.test import TestCase | ||
from django.contrib.auth import get_user_model | ||
|
||
from .models import Server, Channel, Category | ||
|
||
|
||
def user_creator(username="username", email="test@mail.com", password="test_password"): | ||
return get_user_model().objects.create_user(username=username, email=email, password=password) | ||
|
||
|
||
class ServerModelTests(TestCase): | ||
|
||
def setUp(self): | ||
self.owner = user_creator() | ||
self.category = Category.objects.create(name="نوع ۱", description="نوع اول") | ||
self.server = Server.objects.create(name="سرور ۱", | ||
owner=self.owner, | ||
description="سرور ۱", | ||
category=self.category | ||
) | ||
|
||
def test_Server_created(self): | ||
self.assertEqual(Server.objects.count(), 1) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.shortcuts import render | ||
|
||
# Create your views here. |