From 8e60b9cd01b0f6e99a935abfac023c9d484857be Mon Sep 17 00:00:00 2001 From: ilia Date: Sat, 19 Mar 2022 20:23:17 +0300 Subject: [PATCH] add users and change api --- api/__pycache__/serializers.cpython-39.pyc | Bin 935 -> 3649 bytes api/__pycache__/urls.cpython-39.pyc | Bin 456 -> 942 bytes api/__pycache__/views.cpython-39.pyc | Bin 1248 -> 2503 bytes api/__pycache__/viewsets.cpython-39.pyc | Bin 0 -> 1092 bytes api/serializers.py | 74 +++++++++++++++++- api/urls.py | 18 +++-- api/views.py | 34 +++++++- api/viewsets.py | 22 ++++++ chat_models/__pycache__/models.cpython-39.pyc | Bin 689 -> 939 bytes .../migrations/0002_message_time_created.py | 18 +++++ .../migrations/0003_alter_message_author.py | 20 +++++ .../migrations/0004_auto_20220319_1617.py | 30 +++++++ chat_models/migrations/0005_message_tg_id.py | 18 +++++ chat_models/migrations/0006_chat_tg_id.py | 18 +++++ .../0002_message_time_created.cpython-39.pyc | Bin 0 -> 619 bytes .../0003_alter_message_author.cpython-39.pyc | Bin 0 -> 758 bytes .../0004_auto_20220319_1617.cpython-39.pyc | Bin 0 -> 922 bytes .../0005_message_tg_id.cpython-39.pyc | Bin 0 -> 615 bytes .../0006_chat_tg_id.cpython-39.pyc | Bin 0 -> 604 bytes chat_models/models.py | 6 +- .../__pycache__/settings.cpython-39.pyc | Bin 2336 -> 2424 bytes hackbackend/settings.py | 8 +- requirements.txt | 1 + users/__init__.py | 0 users/__pycache__/__init__.cpython-39.pyc | Bin 0 -> 153 bytes users/__pycache__/admin.cpython-39.pyc | Bin 0 -> 194 bytes users/__pycache__/apps.cpython-39.pyc | Bin 0 -> 428 bytes users/__pycache__/models.cpython-39.pyc | Bin 0 -> 1115 bytes users/admin.py | 3 + users/apps.py | 6 ++ users/migrations/0001_initial.py | 32 ++++++++ users/migrations/0002_alter_user_joined.py | 18 +++++ users/migrations/0003_auto_20220319_1617.py | 23 ++++++ users/migrations/0004_user_tg_id.py | 18 +++++ users/migrations/0005_auto_20220319_1853.py | 18 +++++ users/migrations/__init__.py | 0 .../__pycache__/0001_initial.cpython-39.pyc | Bin 0 -> 967 bytes .../0002_alter_user_joined.cpython-39.pyc | Bin 0 -> 589 bytes .../0003_auto_20220319_1617.cpython-39.pyc | Bin 0 -> 689 bytes .../0004_user_tg_id.cpython-39.pyc | Bin 0 -> 597 bytes .../0005_auto_20220319_1853.cpython-39.pyc | Bin 0 -> 609 bytes .../__pycache__/__init__.cpython-39.pyc | Bin 0 -> 164 bytes users/models.py | 20 +++++ users/tests.py | 3 + users/views.py | 3 + 45 files changed, 400 insertions(+), 11 deletions(-) create mode 100644 api/__pycache__/viewsets.cpython-39.pyc create mode 100644 api/viewsets.py create mode 100644 chat_models/migrations/0002_message_time_created.py create mode 100644 chat_models/migrations/0003_alter_message_author.py create mode 100644 chat_models/migrations/0004_auto_20220319_1617.py create mode 100644 chat_models/migrations/0005_message_tg_id.py create mode 100644 chat_models/migrations/0006_chat_tg_id.py create mode 100644 chat_models/migrations/__pycache__/0002_message_time_created.cpython-39.pyc create mode 100644 chat_models/migrations/__pycache__/0003_alter_message_author.cpython-39.pyc create mode 100644 chat_models/migrations/__pycache__/0004_auto_20220319_1617.cpython-39.pyc create mode 100644 chat_models/migrations/__pycache__/0005_message_tg_id.cpython-39.pyc create mode 100644 chat_models/migrations/__pycache__/0006_chat_tg_id.cpython-39.pyc create mode 100644 users/__init__.py create mode 100644 users/__pycache__/__init__.cpython-39.pyc create mode 100644 users/__pycache__/admin.cpython-39.pyc create mode 100644 users/__pycache__/apps.cpython-39.pyc create mode 100644 users/__pycache__/models.cpython-39.pyc create mode 100644 users/admin.py create mode 100644 users/apps.py create mode 100644 users/migrations/0001_initial.py create mode 100644 users/migrations/0002_alter_user_joined.py create mode 100644 users/migrations/0003_auto_20220319_1617.py create mode 100644 users/migrations/0004_user_tg_id.py create mode 100644 users/migrations/0005_auto_20220319_1853.py create mode 100644 users/migrations/__init__.py create mode 100644 users/migrations/__pycache__/0001_initial.cpython-39.pyc create mode 100644 users/migrations/__pycache__/0002_alter_user_joined.cpython-39.pyc create mode 100644 users/migrations/__pycache__/0003_auto_20220319_1617.cpython-39.pyc create mode 100644 users/migrations/__pycache__/0004_user_tg_id.cpython-39.pyc create mode 100644 users/migrations/__pycache__/0005_auto_20220319_1853.cpython-39.pyc create mode 100644 users/migrations/__pycache__/__init__.cpython-39.pyc create mode 100644 users/models.py create mode 100644 users/tests.py create mode 100644 users/views.py diff --git a/api/__pycache__/serializers.cpython-39.pyc b/api/__pycache__/serializers.cpython-39.pyc index 9f6149323ca1f29dba6e4f224c4f01a062eaee7b..5ec4e14c707cf0197af29c965a5bbe69fd3b0be6 100644 GIT binary patch literal 3649 zcmbtWTW=dh6yDjpuW_6-A*Cus++;2R9w-+Th!j+)P%WeukXDga8_zUxvTLU^>y||B zQ~R3#0FU`I{D67oiNAnA@SR!T64$g+Y|Ys@GiPVd`R06QCaKlR7JhAZb2mrt4^n1- zE|e`a^*aQ&I7_XJMJ%%;J98o@b0atNB9GCWo%&f21z8w{Mt9OuR*uS9C8`+RO{-Zg zsxj+Zi+kLEW^rGzr%qId9`F!)X!IrMC0>SJHhKekg;$|hjlK-M#_Q1Q!o~Yd=u5l- zy&-JqE6|sD6M9qB4puR81tTkb6(g(0VvS$9XSLS;L`+u8(@S^zT%`Ae>?UdVL`Yqp z>6f)cJ`Cbp%J_2h#ucbj=DQA z9&Lo$JUZ4cxfNnPMadX4m&q&Ww9i~wr>`uLXpo@c>6eQhg)gfR3=Qd*fTm6%y$me$oiX#Le2x5q_a`go*O|f+ zRR;J%9Orv+m$%P?i|Ipkeu|NOv|aXM|llG+$E>MzFZ zP0UUsr5bn2A{W)p;V!D3i)!a_50%Q-8x-|S^_>EFQl_vsP1Go@zUmKTN6dY6QVw4L z@AZWrnj)vj&wKOJ;%G=c>1%q#N3(QYn&$+cft zYnLqaQpd!`)h*B{}!z<~~rArnda zEh(wxTM$uow5+))%p{39kv@RMhiHm4i-qRzGn-Xe^&j7N|2?^}a050Ax7w}pMUK+} zS$JT4AvYwIbom|$`sR!u<^VCyyoQMunxa5MRxbXwr11{gxgYKD7Mh}zohDgvu@L@2 z@N4)RrIEQ}=n7@cPq^;f1A6b^jpukxRYEslH#+s>PMRnsU&XM2UcOHT4sInnd^iyD z7+0s~#_=)izC@cP9gWS!;9ziz41a)_#xO2H6MD=NWlWx6G8>B0h&<&Hc`76FH0WYA zWzPM*`|<|9BwvR(M-j?5x|nRE8D|zz1miBK;^FDx>5nNhbcXJTHa_=H+0f&`srLle z>0w~VQfh10u%fDvqWLJPbbyOid?=31p6E)#vu>|AI^^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| literal 935 zcmbtS%}yIJ5cc2xKobZp>VY@dOHMsi2#~0RsFYj~7i%TUi4CmqCSWH*zliY9!A>sxSJyWkRL76Snc8AGw zDGZf~VZgy}Km5%x9NC4AnNr$0rN%`XbERgwwo1iyrRup^I<$LAT`#q3Z#gVP3n?;n0HPlNTLJa&~Xzs#r0+RhfCoK&;&LQgLnn1Eqtrqowe36CEI z3&X2#QD9mr@C9sBP6hQFV2tmD&oD}ku!exg&yicJk7o%0?!W+Y+W0Gq{k!&CkL~+U z`9H4EG#&6*E2#gnI;`H~9Q$_&PYQSHL;>*pg;IX=tse$(foy+-L4RCia>v`SP-h;R ze>3-&!%j;)Y8c;7Vf=6;tP8{T(@cVIvP7*ta=n&i%y-*S+QS(QSZ$9E_#k}%9dx{s diff --git a/api/__pycache__/urls.cpython-39.pyc b/api/__pycache__/urls.cpython-39.pyc index 3b413c338a18c656c6aafa80796dce274921be0e..a8592fb045e0741ac2f837bb2bef4dc29c3a58aa 100644 GIT binary patch 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 delta 237 zcmZ3-eu7y$k(ZZ?0SGeYnk1DmGB7*_agYH!kmCTv#W54LRRb6qQW;ZNQdt(TFJx$D z0@-RxU@Gyem9{>vSISK#( diff --git a/api/__pycache__/views.cpython-39.pyc b/api/__pycache__/views.cpython-39.pyc index 08740a07f9423e81ac99915d7680589a18e18c6e..6fac16130310f8f4fd0deb7d37a91a49e7b97f87 100644 GIT binary patch literal 2503 zcmbtVU2oeq6qPL5l0W3gPHe|X_t|2AF(BB(P@u&yWJs~Cz-kQZx&ed%K{44xiD;*k z-6DP6en|J&zogea^)C#2*gcdSIgV3wunb=FT#}cE_g-Fxo>w#I8=CizpHvLvZ-C{` zCU8hC`IiJYxEUMLWTq^!lC+p5ZDz|dE6WP2NQXJ5!AsnVU0G#SSz|Sg?YJ%*tRX$- z$tG)RT{+&8KJ#UZwM^p&gIBoor@%yb)9l{On5%x6h z5N`4`+J0Ud7p4!<9)vO z)EMl)Gsy)5Cv6^`hO?(aMPVGh7AkE$5lIrBh$U6?St8UDZUe6@>*vdkln7_y_h@#C zNs~~Dw2$78mls0C(d1n4B}+c66ia?Rc}Jv-K`FH{kUF{1ft9v?ijsWhcRxS=EfTNN z&M#u7BJol@yWq6vLhWVtatK@4KXn(R$Jk=|D-k%Pmh6!b1~a+AO2T5cD4$i{IDZ+; zQq?|URV1hJZc3=Xg-wWnf<0rVX6q{DpV`UQG{!iD?+f!5Yfu`uj6`$MseVr zYt2;9Y{0dDJ&_-YWTvK>#no2kc zm325Muij^R_TR(kE{%SLt#D;rQvv^PKHZEDF6i<@w}uSr?(OcmN26a;TaW=B4(_D& z;+;scT57?L_H`LOeMX(8*nqXi!~`#oh?9ftFDtyLZLFuLo&?Vox$D(bogbWt2|YvO zL^WUvMOQU3uQA8_vRJQgu)ZC5KXiT8Wlo`XDBMkjyjRFPg{W#*DjZ>5&Zh1+*~|DX Uf~{ZLdnMo8F@4J~ul(%)014UW&j0`b literal 1248 zcmbtUO>fgc5Z(1h?0k}x76jrCf87X^%P0#g;pc^q7!KV~prYHANU$51Eu+~Gy!4lZ=6I#7ww0^KB` zErK=yIjTDZF2Oy5E`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 literal 0 HcmV?d00001 diff --git a/api/serializers.py b/api/serializers.py index a6d0943..899c364 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -1,5 +1,7 @@ -from rest_framework.serializers import ModelSerializer +from rest_framework.serializers import ModelSerializer, Serializer, CharField, HyperlinkedModelSerializer, Field from chat_models.models import Chat, Message +from users.models import UserChat, User +from rest_framework import viewsets class ChatSerializer(ModelSerializer): @@ -12,3 +14,73 @@ class MessageSerializer(ModelSerializer): class Meta: model = Message fields = "__all__" + + +class UserChatSerializer(ModelSerializer): + class Meta: + model = UserChat + fields = "__all__" + + +class UserSerializer(ModelSerializer): + class Meta: + model = User + fields = "__all__" + lookup_field = 'user__tg_id' + + +class UserHyperlinkedSerializer(HyperlinkedModelSerializer): + user_tg = Field(source="user.tg_id") + + class Meta: + model = User + fields = "__all__" + lookup_field = 'user_tg' + + +class MessageCreateWithUsername(Serializer): + author_tg_nickname = CharField(write_only=True) + message = CharField(write_only=True) + chat_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"] + messageModel = Message.objects.create( + text=message, + author=User.objects.get(tg_id=author_tg_nickname), + chat=Chat.objects.get(tg_id=chat_id), + ) + return { + "created_message": messageModel + } + + +class UserViewSet(viewsets.ModelViewSet): + serializer_class = UserSerializer + lookup_field = 'tg_id' + queryset = User.objects.all() + + +class ChatCreateWithTg(Serializer): + name = CharField(write_only=True) + startMessage = CharField(write_only=True) + api_key = CharField(write_only=True) + tg_id = CharField(write_only=True) + admin_tg_id = CharField(write_only=True) + chat = ChatSerializer(read_only=True) + + def create(self, validated_data): + name = validated_data['name'] + startMessage = validated_data['startMessage'] + api_key = validated_data['api_key'] + tg_id = validated_data['tg_id'] + admin_tg_id = validated_data['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 diff --git a/api/urls.py b/api/urls.py index 3e0f62f..cf6704a 100644 --- a/api/urls.py +++ b/api/urls.py @@ -1,10 +1,18 @@ from django.urls import path -from .views import ListCreateMessage, ListCreateChat, RetrieveUpdateMessage, RetrieveUpdateDestroyChat +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 +router = DefaultRouter() + +router.register('user', UserViewSet, basename='user') +router.register('message', MessageViewSet, basename='message') +router.register('chat', ChatViewSet, basename='chat') urlpatterns = [ - path("chat", ListCreateChat.as_view()), - path("message", ListCreateMessage.as_view()), - path("chat/", RetrieveUpdateDestroyChat.as_view()), - path("message/", RetrieveUpdateMessage.as_view()) + path("message-from-username", CreateMessageFromUsername.as_view()), + path("chat-from-username", CreateChatWithUsername.as_view()) ] +urlpatterns.extend(router.urls) diff --git a/api/views.py b/api/views.py index f6a877a..a516b0b 100644 --- a/api/views.py +++ b/api/views.py @@ -1,6 +1,8 @@ -from .serializers import ChatSerializer, MessageSerializer +from .serializers import ChatSerializer, MessageSerializer, UserSerializer, UserChatSerializer, \ + MessageCreateWithUsername, UserHyperlinkedSerializer, ChatCreateWithTg from chat_models.models import Chat, Message -from rest_framework.generics import ListCreateAPIView, RetrieveUpdateAPIView, RetrieveUpdateDestroyAPIView +from rest_framework.generics import ListCreateAPIView, RetrieveUpdateAPIView, CreateAPIView +from users.models import User, UserChat class ListCreateMessage(ListCreateAPIView): @@ -21,3 +23,31 @@ class RetrieveUpdateMessage(RetrieveUpdateAPIView): class RetrieveUpdateDestroyChat(RetrieveUpdateAPIView): queryset = Chat.objects.all() serializer_class = ChatSerializer + + +class ListCreateUser(ListCreateAPIView): + queryset = User.objects.all() + serializer_class = UserHyperlinkedSerializer + + +class ListCreateUserChat(ListCreateAPIView): + queryset = UserChat.objects.all() + serializer_class = UserHyperlinkedSerializer + + +class RetrieveUpdateUserChat(RetrieveUpdateAPIView): + queryset = UserChat.objects.all() + serializer_class = UserHyperlinkedSerializer + + +class RetrieveUpdateUser(RetrieveUpdateAPIView): + queryset = User.objects.all() + serializer_class = UserSerializer + + +class CreateMessageFromUsername(CreateAPIView): + serializer_class = MessageCreateWithUsername + + +class CreateChatWithUsername(CreateAPIView): + serializer_class = ChatCreateWithTg \ No newline at end of file diff --git a/api/viewsets.py b/api/viewsets.py new file mode 100644 index 0000000..70b92f8 --- /dev/null +++ b/api/viewsets.py @@ -0,0 +1,22 @@ +from rest_framework import viewsets +from users.models import User +from chat_models.models import Message, Chat +from .serializers import UserSerializer, MessageSerializer, ChatSerializer + + +class UserViewSet(viewsets.ModelViewSet): + serializer_class = UserSerializer + lookup_field = 'tg_id' + queryset = User.objects.all() + + +class MessageViewSet(viewsets.ModelViewSet): + serializer_class = MessageSerializer + lookup_field = 'tg_id' + queryset = Message.objects.all() + + +class ChatViewSet(viewsets.ModelViewSet): + serializer_class = ChatSerializer + lookup_field = 'tg_id' + queryset = Chat.objects.all() diff --git a/chat_models/__pycache__/models.cpython-39.pyc b/chat_models/__pycache__/models.cpython-39.pyc index 0a5465f1301ccc42ef708b368ab91811eafe1ec3..c40671078de1c487d9a95c843b7e20e8f4895896 100644 GIT binary patch literal 939 zcmZ`%yKWRQ6t(9)o0$-n*EdX)3L1n^!iE4sNkNvz8p-mmt=-woBk|0Nq=t6?0m^&> zf8v%ZC2cB>XQC)Yu;k-=&$aKh@3BbJ5yANV_tk9U5c0=5_lE~(53_vSGtQ7U> z&1l^!-R^z`UO6UiYL4ruP8qLWm*urY^~^D&N?h<#)r)SaBT&a#Y9h{SQ7O*Nh;zJR zU0OTg{Cq9SA)?VdV&bW~=ne~2N+iVzmbRVH9j{c|iiKjKI4k(6x-_H1Myp~`e})}S z_D?4J2k(t9WL4BA#=Z5B#P1fokXJ-ML-rnS-c4TT_6cqNsVqc((9GABs=GFy6?MK8 z^V1$?FjOt`Ia*+EjK1f?vU_%^U1YPuwpROyMl``3)1LpoJYTT+0eJ#R(f-i>21pUX z4piJT9>f@=aS-*bG~iR%fehho%LqcnCOjJ2qwPHwHg9ooe)iCA|HubXdNNZBi* z<32Lj_65h;BfW)HCl*o*Rt>!kFkS~q^p5o(16Y83%SQKaWuEPiNe@J)rbVUtrn97j z$>&;umHLT2`P9Ol27~q7axVb3>Rl(tbcb%!o0JtO8k5#10~uKm-SnxW!VET2T_kmRMSnkzaI+%PqesH8VZWJGHXN7UYmy z?9PtC&W8S%5Z*uE`3|3y1|A`jo6~_rgAfWL0#T5Lq_He5d!FI4hrK?$wh%S6c?=33 zg_3q#s=NXcN@jgQxmoR}`SX4=pUq-1XJo&BJzf9cjQxqhp(zSZ==x&SS#KNERfncWIH!*?GxV)??H6qTf^tJ$=aMFm(`siLq+G=0qs1D|@>xjrnAbYY zbz~cABtO&o^I+=O8zaCSIzU%h^qrv9Li!Tmb$p|fFnHrOIVNFj600Q`&swiBYGvI&-c2#h^zXz H{*k-|eAugV literal 0 HcmV?d00001 diff --git a/chat_models/migrations/__pycache__/0003_alter_message_author.cpython-39.pyc b/chat_models/migrations/__pycache__/0003_alter_message_author.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..783363e06d58856bc8bde10c9262484b2b4a9afd GIT binary patch literal 758 zcmYjP&2H2%5VoD4&8Dq{kf>C+Bkd(xfw)u%b+x4kA$loXqDaP@8L|oaS>ohSu5j&x z@G3ll4_r9$3P}8nlU=%&{KYdK&&>Bt)X`DMXnp_oWc5%m_QM+c%O&HCwvGsZ0WVp_ zV_u0^aBGXwiQN|r9B{udaFG|@XD9YRT(Oz=liskIFkzKvt?Kfo*2b?Iz*1kP_HKU# zWSr5~rv%7i4lEYHL1ZF!&@DV$1N~wG9tOp<@QbiG03Rkd4g@z&#^XbnQq|B*U+>CM zZLinZ>iBp*pFfhS?68&ABa0@l5h&mwU8_!xUBxFuScO`v3}u&BDAN{IhhQdKuklsi zt(*4Er*KFeS)4h>t^2Yx)25ch4?8rXYseiAnPsgiq!5eV`y5NSoE@1!4t^<3C~XIQ ziF7`c@?)<`8*44V4c35lnxk%MM9hQ>OXI?3X`R7w(X^On^((wKJ`}3X8Y5t3f}s9j^N^t>${x3{P?%~cetPVW;*sC!D=8o n5vdqlq*qeTL=x>DeOa@vqT z9}b=;@68O7qdXPKq?#=YENhia(=s^~v$KXwiJ=UWwOJ%L+m_H&9^W#(;o@AH&F;`u zkB9^gv)Mn_cWwIHcmKLx%WbZ6zZ;u@ufw*`AxxW|w4Kp7+$qN-Zw>=csJ#> V+(Xjo;6>a0m!_f0z&7o``46wd2wwmI literal 0 HcmV?d00001 diff --git a/chat_models/migrations/__pycache__/0005_message_tg_id.cpython-39.pyc b/chat_models/migrations/__pycache__/0005_message_tg_id.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..07844469d0be024d6c2ce88c48cd42928299354d GIT binary patch literal 615 zcmYjOO^?$s5cOBuwCqZIV*deBFI8Gt5D1|~MIa9B1vn5zvfPYGQyizni3Df3?w{bs zU-FgH-Z&$nW$Z56PBc&RJeJ?Qi8?->5{%XFv-J;3$ge;SLm)ZFboUT|05zncIc-?Z zD0xMI0sl^bYr5s%c+Nq*C9~uT?~)nw)26OE)z__ce$=#}jVnXzFvdvEG2I+Nlbiy{ z8PJO6T#IcI1oUV-1_23-E*Xq3IrdUWQE1{PZ~iNw+?{fxdb!u}r&*RgkZR~#xy+W! z?Ed1hTs&Mn^5aH3rz-7}zLGUu0qVYs!>TXRXj}CgFYI8_+(WVfCbV?{w#i*QQp*i?$pZZF^U&Yg=qo`6BOcp literal 0 HcmV?d00001 diff --git a/chat_models/migrations/__pycache__/0006_chat_tg_id.cpython-39.pyc b/chat_models/migrations/__pycache__/0006_chat_tg_id.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a3b250764b6aee8290d4f63d7ffb7de5ddfb00a6 GIT binary patch literal 604 zcmYjOJ#Q015Z$k{&nA%~3it;|ZY(#UKnMi|fl`o$kK%OFYJD@D&+P4)+p|RKq|G1T zAMls9r9dguMnYkB4T|?PPxJPT_RY+h!^0_~^ZWLA`GYg|E0X=Ah@4RPX9U22Th{V| zx1tc7y<;FiUNMl!*YZ*p64VDa%WkNa%|w{CP2HQJ>6{Ovwga@jiqifW6FH&qa{^=q z2UZB+H7_Kpbrub9v>t`QytB= z7AZf_`rFpnSQ{DO1|6WQ8uYy&r;xt}cpKm7Wu%kSmFW`?({6+Rw)B(rPe@I0_xbci z`N?DN%QM@U@=aH5TXcgjmyIh|ruv#-NeNk%d$X4hYcFXF&vnw$)bq_nAAjkH!XFXj zQrxRdaY5g~A9bJ9^O*`0SQ}S&b6BSSQ`bp+=x~=krB_1!a<_?BaX23bK9YX{QM074 literal 0 HcmV?d00001 diff --git a/chat_models/models.py b/chat_models/models.py index 2788974..0ed853b 100644 --- a/chat_models/models.py +++ b/chat_models/models.py @@ -5,9 +5,13 @@ 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) class Message(models.Model): text = models.TextField() - author = models.TextField() + author = models.ForeignKey("users.User", on_delete=models.CASCADE, null=True) chat = models.ForeignKey(Chat, on_delete=models.CASCADE) + time_created = models.DateTimeField(auto_now_add=True, null=True) + tg_id = models.CharField(null=True, max_length=100) diff --git a/hackbackend/__pycache__/settings.cpython-39.pyc b/hackbackend/__pycache__/settings.cpython-39.pyc index 84971fc2091b86e68ecbf7b49ce7e8bc93f0f3ca..08243c773bfefd43a6d2e4e461c48232fb78a7cb 100644 GIT binary patch delta 250 zcmZ1=^h1a@k(ZZ?0SFH9m?a&b$ScdZW}%Qi~@4WK!mgVl6FBEh^UJm@LOUQAQOZ zTdbFxnUa!|TAo;xs^<*UG`W&le)D1Gnaqq5lVjO8h)0P!`v(Qb`v-Ztd-}yY`uO;V zgUHFe9LN2iQ s@yT=8H%w0EI4g`kf{Np&Ng(<$h(HF6K#l_t7qb9~6oz01O-8?!3`HPe1o6wx*(xTqIJKxa z#xo}~F~%i7ximL5ucSC8DKjr7BQZG}Oe6srsd*_erC^ou@tJv-e*d=}d literal 0 HcmV?d00001 diff --git a/users/__pycache__/admin.cpython-39.pyc b/users/__pycache__/admin.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..6bbafa6b30d525b2b9d54be4775ce1c3b9c51b30 GIT binary patch literal 194 zcmYe~<>g`kf{Np&NlrleF^Gc(44TX@fuanW zjJH@5Q*tx&{4|-O_)@YG^V0M6lJoOQiZYXmKnAR2C}IXuVB(jxvsFxJacWUT&IYpU!U$7GJ~jt~q>I551;69GXIfa^W;4#8x) zvm2#RKxMr`NWD+i(k6QNoh@gwA3@&OLd(l~-Ib==IGGleyw~f;9#RZU1+pJN>ZWmV u^U?}bp{+TBArE<9Sw+H+cOM~U8_;9K{eN~Fjj`s3XWRMDX^xr4)`7vr|@GJcI3BZqi$Qyu#ctG z`%orG>Z;(XIO2&AHv+PTw&~`{G0&u$R|~^bon^+YReD&<8HIq=Kp)#M1}pmjf?krZ zWJ$rSD+{h=?S2Wc(9_eiXT#I85K_Abh0c@8cs1}U$)$0sIZwqk+_;q4!8Or$A=Qt~ z@v9iOmhrnRP2x#0t8=NUGM=U?UL>bC`$_-+ literal 0 HcmV?d00001 diff --git a/users/admin.py b/users/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/users/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/users/apps.py b/users/apps.py new file mode 100644 index 0000000..72b1401 --- /dev/null +++ b/users/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class UsersConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'users' diff --git a/users/migrations/0001_initial.py b/users/migrations/0001_initial.py new file mode 100644 index 0000000..ca0827a --- /dev/null +++ b/users/migrations/0001_initial.py @@ -0,0 +1,32 @@ +# Generated by Django 4.0.3 on 2022-03-19 12:17 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('chat_models', '0002_message_time_created'), + ] + + operations = [ + migrations.CreateModel( + name='User', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('username', models.TextField()), + ('joined', models.DateTimeField()), + ], + ), + migrations.CreateModel( + name='UserChat', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('chat', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='chat_models.chat')), + ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='users.user')), + ], + ), + ] diff --git a/users/migrations/0002_alter_user_joined.py b/users/migrations/0002_alter_user_joined.py new file mode 100644 index 0000000..1bc4ce5 --- /dev/null +++ b/users/migrations/0002_alter_user_joined.py @@ -0,0 +1,18 @@ +# Generated by Django 4.0.3 on 2022-03-19 12:18 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='user', + name='joined', + field=models.DateTimeField(auto_now_add=True), + ), + ] diff --git a/users/migrations/0003_auto_20220319_1617.py b/users/migrations/0003_auto_20220319_1617.py new file mode 100644 index 0000000..4e12c3e --- /dev/null +++ b/users/migrations/0003_auto_20220319_1617.py @@ -0,0 +1,23 @@ +# Generated by Django 3.1.7 on 2022-03-19 13:17 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0002_alter_user_joined'), + ] + + operations = [ + migrations.AlterField( + model_name='user', + name='id', + field=models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + migrations.AlterField( + model_name='userchat', + name='id', + field=models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + ] diff --git a/users/migrations/0004_user_tg_id.py b/users/migrations/0004_user_tg_id.py new file mode 100644 index 0000000..22bb437 --- /dev/null +++ b/users/migrations/0004_user_tg_id.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1.7 on 2022-03-19 13:21 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0003_auto_20220319_1617'), + ] + + operations = [ + migrations.AddField( + model_name='user', + name='tg_id', + field=models.CharField(max_length=100, null=True), + ), + ] diff --git a/users/migrations/0005_auto_20220319_1853.py b/users/migrations/0005_auto_20220319_1853.py new file mode 100644 index 0000000..cfd40e2 --- /dev/null +++ b/users/migrations/0005_auto_20220319_1853.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1.7 on 2022-03-19 15:53 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0004_user_tg_id'), + ] + + operations = [ + migrations.AlterField( + model_name='user', + name='tg_id', + field=models.CharField(max_length=100, null=True, unique=True), + ), + ] diff --git a/users/migrations/__init__.py b/users/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/users/migrations/__pycache__/0001_initial.cpython-39.pyc b/users/migrations/__pycache__/0001_initial.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ad10d20ddc97f720f58808e927e167de37d45c72 GIT binary patch literal 967 zcmZuwOK;Oa5caM&@gq)~A`a~l34wBn3KAEDP(wmch1yHY#j><=vQu|mKZ4gmv{$(H zFCaMbQ#f+nD<^&d5)zMDyDuR&+R-<&o}KTT*~I<6Z{hm-<jJGj*d zjj#mCtek`-ry(WAradR(jf}$ zEso=wx61U^_V)Heo`X_x0=$+v@I?i24MMY53Mx&dm}$B@9WountGc{8?ky{s$JHr6 zfm7|_r!vmu8R*~*RP#~+FX9}uyTX$Ob<rXqTdEM$#5bs%5~ zg@9rqK~)rosC$z}_nw(}Wt&LwOeSNLJTpYKcL;Cm7WSvuphN6c>-w{@0+|#qu@PO7 z#zj(UD(2d4DC0xY&SZQr8Bd>Uzg)t__pnN1e(p^kN2U)d+RbDfP0Ph9hoV-| zTo%!Byf|sh909V98sX9PJB@IN5BP<)(eku1e*_1&x{Jo8%%*=>hY?C|6QB6M=x^q> z-X_^J-j60@*wtQ3e-`Xa zihp5Weey3TQfK!n?S%c9nQxexZ=x5Af|33C@qD%8jQtG3Lz5Jo&~uLofB|n=$1C0? zRl?aBg9OA41A)8|*P;?2Kd>_WMYXIdphOzvmz|M#b1>Ev*5e!g5TpDJU`XmsmkNcybl zjYYU9xu5H4?3L}Wlm;jTtr*r)R(I%S#PpNF7S79=&sEGT}=<1cR^=G~Q5@AIS4XmTu`u@N*>3*hk7_9=Q_L`5k--hrH!kIQZ7|?D?lKGT2U4Cz+M0eMUgBgGi<%h&tfM?%N4GD z0-k^;Lh_XpuTTlWI1B0?7|WBH`Np1a#*qgH2_yOO{bBi))7Lq>5|DF3+dLoz47{2( zUhXwK=N@~>fP?>qfsfwG|Lo^J1g}{d{-j)%a+@@2sb#Oa*4RnY0oJB+(5|@hC$!Ci z6tdg{mUHlyUhZSC3S9x5to9(F6~YAet^vZ&N;9@p>uds$Zas{eO*)P)AMq#fUIQll}*7$ea-7`s951hn&S553L4k37$-5$=JV`$_C(Ac%^n}EH`@Ij6WZoJ zsmSNQgD~(ot;1hC*3Fo=pn=A)lI^lPf^zI;>|g|M*>0_Sbf1l$ZRhgbHELY@hyEV| Csl7D- literal 0 HcmV?d00001 diff --git a/users/migrations/__pycache__/0004_user_tg_id.cpython-39.pyc b/users/migrations/__pycache__/0004_user_tg_id.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ac4a0181978c3c932af1d3b9e3b179977f203064 GIT binary patch literal 597 zcmYjO&1%~~5Z*u8vPmGP<_!YA7}@C$Ev2L+q~y>LXnPTYW$oF@a#t%yD?xj1u6ckw zLY}B$uRY}z3MHA{v?L>Dm~Up-@0*d@-X0UQUpFrnSCo+70X#K<-~iq2VE_WukecSS zW;vte0|5s7f&kZa&42QogZM-y$t}*33G?H+DqGc6jdgxdH=vDMhSpOXA~-;IQw*Bq z6iCj1mNe&Dtdl^X2kRjSNMLZuV0g)~mqLm}BR~51p8@HT-s#r)-7L%YrRuvz&a?SE z+n>FbvzN11UWC3+x>8nf3rP1lYE<8)(YEYXUfAB42}j*QtF)@tSPL=vT4@8P$e7Al zm(q`=#JS#R%(tXG@0AI&0fF9V3)(I#?OKLRK79{x9NuVofTP2eY9sdJW~2Wd>6*09 zup7glv%@#Vm#|QAVk%V}HOs!%wsXazvc*a*zs0b?1gVO+dhvMg0*~-qhN_JFPB%Z= z@Gl4GZU;lk*_}uPW%zCV6?d_FIuU*ZYh}x33X7;b>W$4uZ4cQlzT(rj4>x!h)^cIh G9exj!b)TdF literal 0 HcmV?d00001 diff --git a/users/migrations/__pycache__/0005_auto_20220319_1853.cpython-39.pyc b/users/migrations/__pycache__/0005_auto_20220319_1853.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5f2d2152b64b5e9c944e7cf6a20e1e2839a54b06 GIT binary patch literal 609 zcmYjO!EV$r5Vd1xn~f;+248@*mnz+|5+H<%ia;Fb1&~k_$@1{S4%GNFpb+-9rLkzzu78$=jq% zID5??0r8E2K)w-QMJYhOW3%*%?y_0p^R}sbJv5zle$sY;#;t;MJ2E0Cv|T}ftmMGT z1bEF$fpU`u1DtI3Ktf7uaw%Z%QjnTKMpjclef!^o4AaqJ@BF=@C?2VhtD#m6co}k^ zMsfvY^nNC&I{if%wDqv|(vHUX$!MGN5u+BWRaUo1TEO&Eg9gsXF;nqeDW5AvU5y4Q zzoXRos7<&V7~mEypj|cS`h*;P{=y8{zY4GPA{M{&hmz9S~$9xt6Kq39Y+-yF}0jl1jtz2dWHyJg`kf{Np&Ng(<$h(HF6K#l_t7qb9~6oz01O-8?!3`HPe1o6w$*(xTqIJKxa z#xo}~F~%i7ximL5ucSC8DKjr7BQZG}Oe6srsd*_erC^o0ndwD|C7Jno#WC^mnR%Hd Z@$q^EmA5!-a`RJ4b5iX