From 132911428646ee91f5a7e98edc880811289c4d20 Mon Sep 17 00:00:00 2001 From: ilia Date: Sun, 20 Mar 2022 15:46:53 +0300 Subject: [PATCH] last commit --- api/__pycache__/serializers.cpython-39.pyc | Bin 3649 -> 4912 bytes api/__pycache__/urls.cpython-39.pyc | Bin 942 -> 894 bytes api/__pycache__/viewsets.cpython-39.pyc | Bin 1092 -> 2788 bytes api/serializers.py | 58 +++++++++++++++--- api/urls.py | 17 +++-- api/viewsets.py | 36 ++++++++++- chat_models/__pycache__/models.cpython-39.pyc | Bin 939 -> 1099 bytes .../migrations/0007_auto_20220319_2234.py | 25 ++++++++ .../migrations/0008_auto_20220320_0005.py | 18 ++++++ .../migrations/0009_auto_20220320_0008.py | 18 ++++++ .../migrations/0010_auto_20220320_0009.py | 19 ++++++ .../0011_alter_chat_id_alter_message_id.py | 23 +++++++ .../0007_auto_20220319_2234.cpython-39.pyc | Bin 0 -> 888 bytes .../0008_auto_20220320_0005.cpython-39.pyc | Bin 0 -> 629 bytes .../0009_auto_20220320_0008.cpython-39.pyc | Bin 0 -> 635 bytes .../0010_auto_20220320_0009.cpython-39.pyc | Bin 0 -> 662 bytes ...er_chat_id_alter_message_id.cpython-39.pyc | Bin 0 -> 716 bytes chat_models/models.py | 6 +- .../0006_alter_user_id_alter_userchat_id.py | 23 +++++++ ...r_user_id_alter_userchat_id.cpython-39.pyc | Bin 0 -> 706 bytes 20 files changed, 220 insertions(+), 23 deletions(-) create mode 100644 chat_models/migrations/0007_auto_20220319_2234.py create mode 100644 chat_models/migrations/0008_auto_20220320_0005.py create mode 100644 chat_models/migrations/0009_auto_20220320_0008.py create mode 100644 chat_models/migrations/0010_auto_20220320_0009.py create mode 100644 chat_models/migrations/0011_alter_chat_id_alter_message_id.py create mode 100644 chat_models/migrations/__pycache__/0007_auto_20220319_2234.cpython-39.pyc create mode 100644 chat_models/migrations/__pycache__/0008_auto_20220320_0005.cpython-39.pyc create mode 100644 chat_models/migrations/__pycache__/0009_auto_20220320_0008.cpython-39.pyc create mode 100644 chat_models/migrations/__pycache__/0010_auto_20220320_0009.cpython-39.pyc create mode 100644 chat_models/migrations/__pycache__/0011_alter_chat_id_alter_message_id.cpython-39.pyc create mode 100644 users/migrations/0006_alter_user_id_alter_userchat_id.py create mode 100644 users/migrations/__pycache__/0006_alter_user_id_alter_userchat_id.cpython-39.pyc diff --git a/api/__pycache__/serializers.cpython-39.pyc b/api/__pycache__/serializers.cpython-39.pyc index 5ec4e14c707cf0197af29c965a5bbe69fd3b0be6..a50ccebb01696917da0a13ee0a64cd112c9d7c3c 100644 GIT binary patch literal 4912 zcma)AOK&5`5uTnmAELO_uC!8;%{q=_6G@Z@k~ndKSoS7s8?YDytJuImz?jSKl_(8K zZO_mf3Eb1>s{ddgb;uv;YfirA7z9YZsu@1S5wjvOHB;3+{iyoBswTT@YgG%M@3r22 z`j2(X`X?!i9~a6VuJm6J(vl*v1|kvzJF*8(-CiIG|La(xZ2YOA`q1Rb& zL0^*%=nduK{SD~rvI)JZZ0L8P-;pioE!8-=2g@cb8}cqJce%$F^m}p>`X=l5p>N6i z(C@RpEw`Uo?VWG2Z>#N__5G1l$rGjf-K2k^w5cvUR~{XA_2a%uq}loS{7mVjKRi`( z`4unkQvYx?N>q2qTH7`*-p)+0uhO)8q+kgDnkvmkm!8_fgkSa5i&SN4kCwCeaiHws zN_QZX6$xoYHnt+9jjhF(LNacPMm#!G#OP`LPN+Gyv>)lHh`4v7{CGSBDEpSH-h1`*&&ZHQ2?UUK7% zG(SS8X-t%Zm>?>bcH|;Hj&uNX+$C|3#4HvI{vbz@+e$ud`^!U;>r8EsqdW$fS9_VT zOsh-DlcA{Fnk=Q=J239ydOh}AQ%24GTN>@QzT7I0^?H9&mc6Y%w`ohu7}aFGF$53L zK-kP7X=~C;oAY4YqfWnpxCTiZpmZ+5aR%sA^8is-dVr`0i2Bk8L<7^Hth z?_fX^YV~~F*GlT|LM_dHTi0$}AAj!Fs5ZvTahx5+ec8Dx!L^22=k7K2WHd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^^5%rRB++c<7pWX-p9L8I5_y z*t{s;Eo>@%KP4-)o(aPc zo?w$iEOSyACP!6MiN<6kVi?C~pr4ck9o~W`xbA;N2dAR@<2Ba6zv?u6^A8%O#%k05 E59{yLrvLx| diff --git a/api/__pycache__/urls.cpython-39.pyc b/api/__pycache__/urls.cpython-39.pyc index a8592fb045e0741ac2f837bb2bef4dc29c3a58aa..24b991e134b6116a6fc4c684b9e4968d6a08d50b 100644 GIT binary patch literal 894 zcmZ8fO>fgc5VaG>AF-W;h*FgkM{;nF2qA<(sgQbr15H6%SwfraBysDtqg|UqZiqAg z0gn8oy>jZ6BPV8@rgE|6=Y2E#-p=eUkK?|D&(}Xs=B{H|zlpS;9+H>%X@ejvVds{# znQha!lXqm7b#dGkPVUGa>q(cn(qo?VnJ)tt$Uf`KkcBd0k!?Zuo5f;?F9xCqJ<${H zcT_jr16O!0?t>@%77xG|L5uex5d9Vpp)aBqk0BIsiw__YgB@R4YzV_2BV701PwHfN zW=%%d*q=4AjkDp^8vpSLEP0(*@5;IYb!}7DH{rPk^*)2EGpNkq4QS0*u;<})&8s~* zoGRcIQ0TQPwg)#;{tJ(}5XmQO8B|i0Nh2RojD)w5 zgF9Xnru6ox30JEm6BOe@W<_J6-%iFR6c@Z$mB+Qpwd&vwvj+-v^>L}No~u$_9;;^e zwdzvRrz)^tt>{)Nm%t^5RALi8(+aH(|C?1#I^8*aad^M!siMKf!l=z z{Ib*`2?_o_ojyy?u>qZ)<{3{<%0(@qsB}8dige8vmkrEufclhgvXm^2H(!kZT$ZBF X;RW3o{SYCtBl~gJ?TqZZuVeoM_j?8L literal 942 zcmZWnO;6iE5cS%Q?Zl2r0tD!#=Nv#ip{lB?N}x)WS`HvuX=Mp**dZ}^<7n4`!j*IX z104HT`V;or6MvzHsxu~(M0J#>dCzY?c0HoqZaMfIu-)OV=QzKJEIth+@9}SbB1lKF z!cmMf=15n1g{wU7DWChQ!5b>zfeLx3A|9zGZ>kn=shGzq;YscHi?&L6im@Xb#fs|i zPOS$;mvq(RJ+;bLnFF0$hp)lf`ML}tm7$Ejd#Dm`LQggqcnel#YtEUBA-?P1JGU+{ znLzRwk6gY18+V(SzjaTOw~w4b`he$g2F&_XQH>uMk(TX#%1yPWK~(S=j1eQS>9e#q z7L{E;gi7ad3CB~pVB1=j_rX-Uysk5P&lQdh=vrH-N}BC2r~mWy{@3l+(tsaysmMMN z3T*%J6}9-9SK}ugj~P?^C5NjcsF1ez;Y`em>ad(upa-5#@d9i*KlI#ZV=DAS{25lj z)MzLS)ZIcgza#$?eK+fKx_yQtZIhc^H$8f}tQ`zq*jS#6$*A0!>B4B2x;HLyJfnS# zHLaZv2ttC0ph-a6s$+tLpp9T-Y?X^5zX5IPgYdq_`#(9;*#D~37dyH>rqL^C=TY4U zDx*78qDv)$M~96xjBo|;i-f|QkkQ6CA?^rj6JrDTR>4GCpT_>-=$BN1;P>mjHyPcr z$vzgj$o9+AnSx1WvSB{S#^Us%h9L%+pNVOnQHh=DwT<4YQqBr^M@win5fb*wO<2O# O+`#QH{CUX!`2JsoZyALE diff --git a/api/__pycache__/viewsets.cpython-39.pyc b/api/__pycache__/viewsets.cpython-39.pyc index fd010420f1098093ca33bb6d5babe0583bc0cf73..ecd8f493df15e47f1811c84946e47837d2ef0605 100644 GIT binary patch literal 2788 zcmbtW&2Jk;6rb5$+w0Fb&WDqJK=_c5p+pr(JwOx%rK0K~Mrr~`Bcs*EGjZ15^*S@_ zhD6B$C07pIIkd<8OLOJaE8IBo-q=poDF#Z{n&*ALnR)Z(eXd_F7YIB*{r+hG%N!xU zA(MVGz-+-#gc8CDry+?bqmjidio6xtk;5GGZiksD%d%09<$!m1CUm1b%SQ!Ph>ENj zl~^e%vvO2n6|+7Y&P7#LrQ`|WIqqH(?h4wSzpz;ikUTE{QWzr(fE0NNkkS}g1f zfK-IlT>^CZ!eMnl=Xe#+Y6@Kebe`7$t)gPlEb}@UL9|`0a0q-kA$v&#W^y2@w60B%zY-*Anq&C zM(xv&1%B-ECb&`QO3CcSWKzNyiI#vr*8l z=b;9krwg7J#e5jzd&%>ThJHAjkuJ#BRoFhhzSj|H96e`9UdW~Sh5 zwMuZ%Y_%}=-i0wy3;8!zYjG<5XRA{FM^#Xb4^pZi|C%b-MFWF%+F#tdBrL;i@SCGo z(OZ-Hv=>i`2PAVFMNA%yCmY5$Fw}=Y&TLLs$+?q|F6~-p4!3@$=b6Oj_F1Ou1oVQU z_@=f7JuGfRCn9>-I5VJN&~hn$fgYUlKfb_opVJil7MSVs={mR>; zNK60|HoEBZDCm3UHlzBC@pS7xdW@Ay4Z&SnM{~2gNde#uzuWwmFdc(hGc5I zsh*}*VTkJb^r>LL(N~1A4J+;736s`=t;zH#i6vfFMCzMflX%#3)l(imJ3kt8~pO*|jYGmL2oU{{{MQ BO`iY& literal 1092 zcmbtTJ#W-77`F5Mb?Nmeu(99LjRjQ*sYr;ST~07qk)mAewz+dIS37A{RuI1fMt%eT z#4A%rRwmvzm*Z|g0;!Jj-0R1V{rK^7#b^`}Xy1Q6pMSOp`GKAN=0N8ay!r-!6HX`kWB1UHqq)uPo1N^ z@IA_SQtTz5jb|i&d+$ zd9})}igMY*915}GS+TCNt*OWBJB49DJ=y~Zr~^;WJFjK&62YSa)go$@~(tW}<=AvGc noZ&~?li`*37AjQmH-k-ZvWf0X{C8=*w1g&fOpok|H}QT0>ICjd diff --git a/api/serializers.py b/api/serializers.py index 899c364..22192d4 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -1,28 +1,37 @@ -from rest_framework.serializers import ModelSerializer, Serializer, CharField, HyperlinkedModelSerializer, Field +from rest_framework.serializers import ModelSerializer, Serializer, CharField, HyperlinkedModelSerializer, Field, BooleanField from chat_models.models import Chat, Message from users.models import UserChat, User from rest_framework import viewsets -class ChatSerializer(ModelSerializer): - class Meta: - model = Chat - fields = "__all__" - - class MessageSerializer(ModelSerializer): class Meta: model = Message fields = "__all__" + depth = 1 + + +class ChatSerializer(ModelSerializer): + message_set = MessageSerializer(many=True, read_only=True) + + class Meta: + model = Chat + fields = "__all__" + depth = 1 class UserChatSerializer(ModelSerializer): + class Meta: model = UserChat fields = "__all__" + depth = 1 class UserSerializer(ModelSerializer): + admin_chats = ChatSerializer(many=True, required=False, read_only=True) + viewers_chats = ChatSerializer(many=True, required=False, read_only=True) + class Meta: model = User fields = "__all__" @@ -42,16 +51,19 @@ class MessageCreateWithUsername(Serializer): author_tg_nickname = CharField(write_only=True) message = CharField(write_only=True) chat_id = CharField(write_only=True) + message_id = CharField(write_only=True) created_message = MessageSerializer(read_only=True) def create(self, validated_data): message = validated_data["message"] author_tg_nickname = validated_data["author_tg_nickname"] chat_id = validated_data["chat_id"] + message_id = validated_data["message_id"] messageModel = Message.objects.create( text=message, author=User.objects.get(tg_id=author_tg_nickname), chat=Chat.objects.get(tg_id=chat_id), + tg_id=message_id ) return { "created_message": messageModel @@ -66,7 +78,7 @@ class UserViewSet(viewsets.ModelViewSet): class ChatCreateWithTg(Serializer): name = CharField(write_only=True) - startMessage = CharField(write_only=True) + start_message = CharField(write_only=True) api_key = CharField(write_only=True) tg_id = CharField(write_only=True) admin_tg_id = CharField(write_only=True) @@ -74,13 +86,39 @@ class ChatCreateWithTg(Serializer): def create(self, validated_data): name = validated_data['name'] - startMessage = validated_data['startMessage'] + startMessage = validated_data['start_message'] api_key = validated_data['api_key'] tg_id = validated_data['tg_id'] admin_tg_id = validated_data['admin_tg_id'] + print(name, startMessage, api_key, tg_id, admin_tg_id) chat = Chat.objects.create(name=name, start_message=startMessage, api_key=api_key, admin=User.objects.get(tg_id=admin_tg_id), tg_id=tg_id) - return {'chat': chat} \ No newline at end of file + return {'chat': chat} + + +class AddUserToChatSerializer(Serializer): + chat_tg_id = CharField(write_only=True) + user_tg_id = CharField(write_only=True) + + added = BooleanField(read_only=True) + + def create(self, validated_data): + chat_tg_id = validated_data['chat_tg_id'] + user_tg_id = validated_data['user_tg_id'] + + Chat.objects.get(tg_id=chat_tg_id).viewers.add(User.objects.get(tg_id=user_tg_id)) + print(Chat.objects.get(tg_id=chat_tg_id), User.objects.get(tg_id=user_tg_id)) + return {"added": True} + + +class FromUsernameToTgSerializer(Serializer): + username = CharField(write_only=True) + user = UserSerializer(read_only=True) + + def create(self, validated_data): + username = validated_data["username"] + user = User.objects.get(username=username) + return {"user": user} diff --git a/api/urls.py b/api/urls.py index cf6704a..70ed35a 100644 --- a/api/urls.py +++ b/api/urls.py @@ -1,18 +1,17 @@ from django.urls import path -from .views import ListCreateMessage, ListCreateChat, RetrieveUpdateMessage, RetrieveUpdateDestroyChat, \ - ListCreateUserChat, ListCreateUser, RetrieveUpdateUserChat, RetrieveUpdateUser, CreateMessageFromUsername, CreateChatWithUsername -from .serializers import UserViewSet from rest_framework.routers import DefaultRouter -from .viewsets import UserViewSet, MessageViewSet, ChatViewSet +from .viewsets import UserViewSet, MessageViewSet, ChatViewSet, CreateChatFromTgViewSet, \ + MessageCreateWithUsernameViewSet, AddUserToChatViewSet, FromUsernameToUserViewset, FromTgIdToChats router = DefaultRouter() router.register('user', UserViewSet, basename='user') router.register('message', MessageViewSet, basename='message') router.register('chat', ChatViewSet, basename='chat') - -urlpatterns = [ - path("message-from-username", CreateMessageFromUsername.as_view()), - path("chat-from-username", CreateChatWithUsername.as_view()) -] +router.register('chat-from-username', CreateChatFromTgViewSet, basename='chat-from-username') +router.register('message-from-username', MessageCreateWithUsernameViewSet, basename='message-from-username') +router.register('add-viewer-to-chat', AddUserToChatViewSet, basename='add-user-to-chat') +router.register('from-username-to-user', FromUsernameToUserViewset, basename='from-username-to-user') +router.register('from-tg-id-to-admin-chats', FromTgIdToChats, basename='from-tg-id-to-admin-chats') +urlpatterns = [] urlpatterns.extend(router.urls) diff --git a/api/viewsets.py b/api/viewsets.py index 70b92f8..8acb423 100644 --- a/api/viewsets.py +++ b/api/viewsets.py @@ -1,7 +1,9 @@ -from rest_framework import viewsets +from rest_framework import viewsets, mixins from users.models import User from chat_models.models import Message, Chat -from .serializers import UserSerializer, MessageSerializer, ChatSerializer +from .serializers import UserSerializer, MessageSerializer, ChatSerializer, ChatCreateWithTg, MessageCreateWithUsername, \ + AddUserToChatSerializer +from rest_framework.response import Response class UserViewSet(viewsets.ModelViewSet): @@ -20,3 +22,33 @@ class ChatViewSet(viewsets.ModelViewSet): serializer_class = ChatSerializer lookup_field = 'tg_id' queryset = Chat.objects.all() + + +class CreateChatFromTgViewSet(mixins.CreateModelMixin, viewsets.GenericViewSet): + serializer_class = ChatCreateWithTg + + +class MessageCreateWithUsernameViewSet(mixins.CreateModelMixin, viewsets.GenericViewSet): + serializer_class = MessageCreateWithUsername + + +class AddUserToChatViewSet(mixins.CreateModelMixin, viewsets.GenericViewSet): + serializer_class = AddUserToChatSerializer + + +class FromUsernameToUserViewset(mixins.RetrieveModelMixin, viewsets.GenericViewSet): + serializer_class = AddUserToChatSerializer + + def retrieve(self, request, *args, **kwargs): + pk = kwargs['pk'] + user = User.objects.get(username=pk) + return Response({"tg_id": user.tg_id}) + + +class FromTgIdToChats(mixins.RetrieveModelMixin, viewsets.GenericViewSet): + serializer_class = AddUserToChatSerializer + + def retrieve(self, request, *args, **kwargs): + pk = kwargs['pk'] + user = User.objects.get(tg_id=pk) + return Response({"chats": [{"api_key": i.api_key, "name": i.name} for i in user.admin_chats.all()]}) \ No newline at end of file diff --git a/chat_models/__pycache__/models.cpython-39.pyc b/chat_models/__pycache__/models.cpython-39.pyc index c40671078de1c487d9a95c843b7e20e8f4895896..982dc84050f93fde43a4b15696d887f391deee73 100644 GIT binary patch delta 663 zcmZuvy>8S%5cYcge?I#N5m87AI%ElPLW-ymN_EiW8d6zED<`wu`B>XxZIe)40d0!Y z!9ySUa!;Cp03RarWGvBViZ}#V#|076>@i?+@yq!J0nDR|>ygtPWEMUs2 zSk4&bwz4apb7sA;fP?eN0!Oly^O5H+GA?+?css@e|CN;mwslpc)(-~{teH^SSM)DAb=3-6e2VlZGIlF^HBj+ zS&PeM(X|;jVN(lqm7O$B-795cEmhG;5Oq<>TRFr&*tX6R;w z`8-Q?LenY1guo`agJ7IaUU&K~)%ys!SM=So(Ww5*ez?9z`~ktAmi}h|7DVFN$Ud=tW|s29y+xEKtLL)W`IgfqHxO}iVG|4-ip2hZ?n^h!QwmS+Z2AY_*g$m7GK>QwLa!s4^n4 zFjf2neggl%|DYo)6X$?BVd5Ou`O|*4{K)eh1n1-Hs5>PyfA{hbGLATo(GZ6i zqYK0dr;mtJfd}M)h7=ToGf>!{VsP^s1=d0v1z4HG5f^bMNpqV5H6T*Grj2dvLe#LN#S58O48*oHivzlM zUI8AE(oyQ-R=XF)JQk-IAqS;;WtZ0M EA4id7_W%F@ diff --git a/chat_models/migrations/0007_auto_20220319_2234.py b/chat_models/migrations/0007_auto_20220319_2234.py new file mode 100644 index 0000000..67fc6e6 --- /dev/null +++ b/chat_models/migrations/0007_auto_20220319_2234.py @@ -0,0 +1,25 @@ +# Generated by Django 3.1.7 on 2022-03-19 19:34 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0005_auto_20220319_1853'), + ('chat_models', '0006_chat_tg_id'), + ] + + operations = [ + migrations.AddField( + model_name='chat', + name='viewers', + field=models.ManyToManyField(null=True, related_name='viewers_chats', to='users.User'), + ), + migrations.AlterField( + model_name='chat', + name='admin', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='admin_chats', to='users.user'), + ), + ] diff --git a/chat_models/migrations/0008_auto_20220320_0005.py b/chat_models/migrations/0008_auto_20220320_0005.py new file mode 100644 index 0000000..b3f7edd --- /dev/null +++ b/chat_models/migrations/0008_auto_20220320_0005.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1.7 on 2022-03-19 21:05 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('chat_models', '0007_auto_20220319_2234'), + ] + + operations = [ + migrations.AlterField( + model_name='chat', + name='tg_id', + field=models.CharField(max_length=100, null=True, unique=True), + ), + ] diff --git a/chat_models/migrations/0009_auto_20220320_0008.py b/chat_models/migrations/0009_auto_20220320_0008.py new file mode 100644 index 0000000..e53a960 --- /dev/null +++ b/chat_models/migrations/0009_auto_20220320_0008.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1.7 on 2022-03-19 21:08 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('chat_models', '0008_auto_20220320_0005'), + ] + + operations = [ + migrations.AlterField( + model_name='chat', + name='tg_id', + field=models.CharField(default='1', max_length=100, unique=True), + ), + ] diff --git a/chat_models/migrations/0010_auto_20220320_0009.py b/chat_models/migrations/0010_auto_20220320_0009.py new file mode 100644 index 0000000..001f545 --- /dev/null +++ b/chat_models/migrations/0010_auto_20220320_0009.py @@ -0,0 +1,19 @@ +# Generated by Django 3.1.7 on 2022-03-19 21:09 + +from django.db import migrations, models +import uuid + + +class Migration(migrations.Migration): + + dependencies = [ + ('chat_models', '0009_auto_20220320_0008'), + ] + + operations = [ + migrations.AlterField( + model_name='chat', + name='tg_id', + field=models.CharField(default=uuid.uuid1, max_length=100, unique=True), + ), + ] diff --git a/chat_models/migrations/0011_alter_chat_id_alter_message_id.py b/chat_models/migrations/0011_alter_chat_id_alter_message_id.py new file mode 100644 index 0000000..9159951 --- /dev/null +++ b/chat_models/migrations/0011_alter_chat_id_alter_message_id.py @@ -0,0 +1,23 @@ +# Generated by Django 4.0.3 on 2022-03-19 21:18 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('chat_models', '0010_auto_20220320_0009'), + ] + + operations = [ + migrations.AlterField( + model_name='chat', + name='id', + field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + migrations.AlterField( + model_name='message', + name='id', + field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + ] diff --git a/chat_models/migrations/__pycache__/0007_auto_20220319_2234.cpython-39.pyc b/chat_models/migrations/__pycache__/0007_auto_20220319_2234.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b422dd2bff01bd7149dc9d49d7dbbba0a589d58e GIT binary patch literal 888 zcmZ8fNpI6Y6dsSqj^iW^H$ZTJV=h*j(6R`jMkz%IwU@RWEQ^toH%)E41TUa)g=>BY ze`&6q_zRVacr#9EV5E8Tw)x%~_IfVCb3WXk873h=m9Tvn3I}*g4+#)35|SFeky4); zN~VeFvo{1xVBZNaVZ_!q)3<=0l7aOL|BwNdZW=9$u!{1mly;hfNXnDBvTYxg#{u5* zJrY5D1Bg$-0J@;QDOhZ&7{ZQQV1W%SaMmWY*UI9c#YIaSEaAqT*p9n#4?56=-kK>N zMA(5H%&0Hh$2X~9URGU-qV(?$hr>M{)>Y0&!_jCs-hIw@pY4s&qcgt@E8e8+_t9^k zYfZJ_5lE(Z+4>xbFNkv{dmB#slwVy9@10|ifhk#5CyDG9A_*%2JPT7HX_ceJ)%cBu zX}xt3i3Fq-LKMfDp7P$F1koguvUj_OwOgtRSk6_kneK- zsSXnrM@b--A_I}lBT*Jq!8sFvBNe~Eg&?wj9A>MtTv4r+?j*rT8~!LSM6}4>iIub= z4zoorDa@p!^TC13)^u_@ogBWFZoU+oCHO&#M+mLS)raYeK((k0-X>8P9Om;n6|8Ue z;qG0tEA2V3WxJ`vgPHC}(}nwgm0q(A-c5zY167KOa$8ixJw}~$UN)V7rJ7kPw>ySo F{sGSL`y&7V literal 0 HcmV?d00001 diff --git a/chat_models/migrations/__pycache__/0008_auto_20220320_0005.cpython-39.pyc b/chat_models/migrations/__pycache__/0008_auto_20220320_0005.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b95a8f6d2ee903d44a650ec815f9b3fc1b4cf50b GIT binary patch literal 629 zcmYjO&2H2%5Vm6{&88IfR-OQ9FIAfITUAw2DTo8TKrc~L%bPLTERM5{6N#S7wGToM zJdm%P`U*&>jI*Gwt@$)F-^kz0SZ-}41kdg1i`h>~$S)tPACAE>nth4@1gItr&1nkE@|qjlYQM9>!PLwrETe{^%G-ojAl~=MRE!x z4}exQXNoUEFQB5u25<=RMmG#LZWyvL#3(g!laK#3P;j%H%U-OM+)kRNFNGZXR%B_G zrTcrYMV9S9bKFgSG|L2DNcroJ51$obxdk&QymWB8?3 z8qQEZ7Gqurmk6&sXodbGAub20eXWl`EtLUf%39ejKt-3l(Y@;4`BysT6O)sj=$mBg8DY=OL#7-p7CV{m7n8xtqX3nyTG}**MAA{YXA^y7Hdj RD=t1@VhQsTBYK literal 0 HcmV?d00001 diff --git a/chat_models/migrations/__pycache__/0009_auto_20220320_0008.cpython-39.pyc b/chat_models/migrations/__pycache__/0009_auto_20220320_0008.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..6bc28b09c9848b07594ba1b38b606e665c32c77a GIT binary patch literal 635 zcmZWm&2H2{44%nMvPqz*H{b=3a;d^1P(c+cYH7uRUVuv!F`A9tY?l0NGl>LedhLU7 z<9X)FsjpB86;Bq_mGH=x?a%UOd-Tpu%t+pzyjc9?jQw)Kwnz#NNzD^7z<}4R;Tdnd z%;W5ofd}G}fk3_z-$f=seqf1zO|>lXY}{03uZOB@jSZR(ur`H*wk4$Ckkq7PkYyZL z<^eBxCQzP-V0I-Syb^?l5D`^uqxb(fi11#q)PveE*@tPG?khbGotmff zdHQUgDoQ=K(p6c1C{+cPKfMNG{+I|m13cGbJ<#0xtE#arhoue1wz?RR;CSk*THT

FFzpE>qA9uyrU^|$6QMLI}7hfi`Acx5Et%Kxu zzmd}&UjBcY{k`?K-u-w$YIezl!n>8emV>?Upod^K;PvPy%5C_<=JQ4t4v0WML5<;}R+EKahG69i|t_Ca_L zp2Am7eFY>`##vBTVxsvpfA%*sjygPy3CgGQC#xTnke}Y!7lF~FWOOoIQ&ya+@w=W?&C#W_< z&?Kioat5@bIoDzn00XXPo4F1*5eNuicFkda%`qQCh-{II-u$CM&VzET2Du}157IO} zmTDY2nWb5lKF(5!p{GvxDi;iutl& zhd{iNubg;=N(jc@Mco5qc{Jns;`zRD{dCE`MU+j zkOd9Tc)(sW;1GUg5MrWY1yl;HFnT+fVC-IY2RG?6WV4$ z4p|le%Qys8kcAj6W7hx&%OOOxVi>^iHiFUZwl@BMt>W1T5+X9OYRC3~^u zVIQRFaVq4x@5DTv&(kOKRHSM8%tj7nxq|l>mS3LFB0Ke{Qlsn<>|~`?BlSjHl6WWBXEt(YHvXuv20Luf7+K+BHnt<-0YcbBIA-e_DV_@P zX)SB_k;?#A*aEhtLZj)Cm`zUW9`%L0PKWMb`bt%&q{ScEq+8)`?mw7*NC5BdmS@lN z55(Bym$j1lc~`C*Y9-&~D?PLiBN2`r? zKhA)*c|>j$@;^}=1)SF5@4e{G;}$gJF)U?Ubw^NmiC&g3-t*r^?mjzuu^rY+r{1`k H9EN`ZU~|VS literal 0 HcmV?d00001 diff --git a/chat_models/models.py b/chat_models/models.py index 0ed853b..5235750 100644 --- a/chat_models/models.py +++ b/chat_models/models.py @@ -1,12 +1,14 @@ from django.db import models +from uuid import uuid1 class Chat(models.Model): name = models.TextField() start_message = models.TextField(blank=True) api_key = models.TextField() - admin = models.ForeignKey("users.User", on_delete=models.CASCADE, null=True) - tg_id = models.CharField(max_length=100, null=True) + admin = models.ForeignKey("users.User", on_delete=models.CASCADE, null=True, related_name='admin_chats') + tg_id = models.CharField(max_length=100, unique=True, default=uuid1) + viewers = models.ManyToManyField("users.User", null=True, related_name='viewers_chats') class Message(models.Model): diff --git a/users/migrations/0006_alter_user_id_alter_userchat_id.py b/users/migrations/0006_alter_user_id_alter_userchat_id.py new file mode 100644 index 0000000..afbcddd --- /dev/null +++ b/users/migrations/0006_alter_user_id_alter_userchat_id.py @@ -0,0 +1,23 @@ +# Generated by Django 4.0.3 on 2022-03-19 21:18 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0005_auto_20220319_1853'), + ] + + operations = [ + migrations.AlterField( + model_name='user', + name='id', + field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + migrations.AlterField( + model_name='userchat', + name='id', + field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + ] diff --git a/users/migrations/__pycache__/0006_alter_user_id_alter_userchat_id.cpython-39.pyc b/users/migrations/__pycache__/0006_alter_user_id_alter_userchat_id.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..bedc42c1e3e8d46ea4faf166d1af4cc1cdb62d96 GIT binary patch literal 706 zcmZuv&2H2%5O$noo1|N*Hv|uWw3jN~suduFTBr&=uovJGMY6n^Ve4&v7CS*&u5j&% zH{ixA`O1k`sDxnb1$7UM<Fy5Y(&* zilE^I57{C_;>uu`7V1{BO$5o!CYSy{x8Owr88xzN)7SqxpmyTHpf>hi zp6ACx4t*!4`E;5e9X=L^kB*OQ_<@qGCV~?sd${xY)uC!{TUW;p7+mx_M z*6I`5@kiA2&Y);zgOiYGJF4EZk&D^*y}}x7;tEt(vY$;-n+T5(!e&CyiJ?Za$3lD< zWbIBl4{(JoU|T6Pn%;-m?5yrlU%2~p=mO*CYH>zne8^_q3jdD$JJa_G;MFa@cv8M| z^vlay$@09bh6dZ-lylXVSF*bHYEA~#EB&C#yVomeWG6zp%EIM@f-TQ6qR7E&t=)GS z(KZiAB_aPE#Zka%?f=@cZar>B15RNn+eLQ(bI;B*^2xi_H