Created
June 20, 2019 14:52
-
-
Save UlvacMoscow/b3d8911d2334ed1609c970e3a5c64942 to your computer and use it in GitHub Desktop.
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
#my view | |
from django.contrib.auth.models import User | |
from django.contrib.auth.forms import UserCreationForm | |
from shop.signals import * #мой сигнал | |
class CodeCompare(View): | |
def post(self, request): | |
body_unicode = request.body.decode('utf-8') | |
body_unicode = json.loads(body_unicode) | |
email = body_unicode['email'] | |
phone = body_unicode['phone'] | |
code = body_unicode['code'] | |
form = UserCreationForm({"username": email, "password1": phone, "password2":phone }) | |
if form.is_valid(): | |
form.save() | |
#my signal | |
from django.db.models.signals import post_save | |
from django.dispatch import receiver | |
from django.contrib.auth.models import User | |
@receiver(post_save, sender=User) | |
def create_customer(sender, instance, created, **kwargs): | |
print('Сигнал о том что пользователь создан') | |
print(instance.username) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
В первой части кода есть переменная code, и я ее не буду записывать в User, будет еще ряд параметров которые я туда не буду записывать. Но в сигнале я буду обращаться к новой модели Customer и создавать еще один экземпляр, и я хочу записать все параметры которые придут ко мне с фронта, обращаясь к instance я могу достать лишь те поля которые записаны в User, а как передать еще ряд значение в сигнал во время вызова сигнала?