inchidi
so you have 2 choice, but personally i prefer 1st one
Anonymous
or, dont use ModelForm i think
what's your suggestion?
inchidi
first one
inchidi
your form will be reusable with that kind of code
inchidi
lol no
inchidi
something like {% if user.user_type ==1 %}....
Anonymous
something like {% if user.user_type ==1 %}....
🤔 this is register page, i should think more about it
Anonymous
am not trying by myself but from code you provided i can see thats the wrong part i guess
what's yout point of view about this error: ValueError: Cannot assign "<User: normaluser>": "User.user" must be a "SuperUser" instance. happend in : User.objects.create(user=user).save()
inchidi
🤔 this is register page, i should think more about it
i thought its "create new user" after user login page. so its easier then coz you just "not showing admin user_type"
Anonymous
^ @MrVvVrM
🤔 it's for save user and that one you mentioned for check user existence i don't understand very well 🙁 sorry
Komang
Lol
Komang
nope
I think you can follow @inchidi change to filter
inchidi
🤔 it's for save user and that one you mentioned for check user existence i don't understand very well 🙁 sorry
if you want to check for certain username used, you can use User.objects.filter(username=user.username).exists()
Anonymous
I think you can follow @inchidi change to filter
😅 i want but i don't understand why my code is wrong and why i should change it 🙂 i want to learn not just make it correct
Komang
That answer for your problem
inchidi
or relationship to user
Anonymous
That answer for your problem
oh men sorry my bad i have this class NormalUser(models.Model): user = models.OneToOneField( User, verbose_name=_("User"), on_delete=models.CASCADE, unique=True, ) phone_number = models.CharField( verbose_name=_("Phone number"), max_length=11, null=True, blank=True, validators=[RegexValidator(regex=r"^[0][9][0123][0-9]{8,8}$")] ) def __str__(self): return self.user.username
Anonymous
i have user that related to User model
Anonymous
i have 3 type of user , it's my whole model code: https://beepaste.io/view/WpXyBX
Anonymous
😞 sorry i bother you with my dommy questions
Anonymous
User should be a subclass of auth_user_model
i inherit it from abstract user django
Anonymous
So burn your spirit brother
😅 not that much bother
inchidi
is this registration form for normal user only?
Anonymous
is this registration form for normal user only?
nope i want to use this form for normal user and developers
Anonymous
class Meta: model=User i wrote this in my form
inchidi
nope i want to use this form for normal user and developers
both have different fields, which fields gonna show on your page then?
inchidi
or simpler: dev doesnt have phone number, will your form page have input phone number form?
inchidi
or simpler: dev doesnt have phone number, will your form page have input phone number form?
if yes then you cant use ModelForm, if no then you must have 2 ModelForm
Anonymous
or simpler: dev doesnt have phone number, will your form page have input phone number form?
i want to show user a radio box to choose between developer and normal user and i show fields to he or she i think all field is same but some thing in developer is requierd but in normal not
Anonymous
both have different fields, which fields gonna show on your page then?
i am in testing phase and i comment those fields for normal user but it's same yet
mλdcodez
KeyError at /blog/10/share/ 'to'
mλdcodez
:/
mλdcodez
line 29 send_mail(subject, message, 'admin@myblog.com', [cd['to']])
Code9
While adding a type option
Anonymous
What about making it the same class
🤔 you mean make one type user and add a field to class?
Code9
if user._type == User.DEVELOPER: do_stuff()
mλdcodez
Anonymous
then you can handle that on javascript side, you must create 2 ModelForm for normal user and developer user
🤔 oom, make sense, and should i show two template for normal and developer seprately?
inchidi
if user._type == User.DEVELOPER: do_stuff()
^you can do this but you cant use ModelForm, if you are insisting then you will write long and complicated code am sure
Komang
this is source
Yes you can debug your code with print 'cd' object and make sure you form key 'to' already exists
Anonymous
can i send two form as context in one template?
inchidi
😅 very good, thank you very much 🙂 i should try this ways 🌹
you should try both if its for learning purpose i think
Komang
@inchidi the real master
Komang
_/\_
inchidi
can i send two form as context in one template?
i think no, you must create your own radio button i think
Anonymous
i think no, you must create your own radio button i think
🤔 understand django is hard 😄 but sweet
mλdcodez
Print object cd before line 29 for debug
dubug: {'name': 'testing name', 'email': 'somemail@gmail.com', 'comments': 'some text'}
mλdcodez
mλdcodez
Maybe you mean 'email' not 'to'
works Thanks E-mail succesfully sent "Share Test" was succesfully sent to . 'to' was written in book 😅
Django Bot
>> Links - Do you know less obious features of Django ORM? - Continuous Integration and Deployment with Drone, Docker, Django, Gunicorn - Django development with Docker —A completed development cycle
Franz Emil
??
Django Bot
>> Links - Django: How to Extend The User Model (aka Custom User Model) - William S. V - Django Login/Logout Tutorial - William S. Vincent
Someone
Hi, I have raised a ValidationError in models clean function .. it is giving 500 error.. but i want to handle it in DRF with a message.. i searched a lot but could not get anything which i understands.. how can i attain this?
Someone
raise ValidationError("your message")?
I did this.. its giving 500 error..
inchidi
I did this.. its giving 500 error..
what http status you want to pass?
inchidi
oh, make sure its ValidationError from drf, not from django
Someone
what http status you want to pass?
I need to handle this like it gives a error in drf
Someone
oh, make sure its ValidationError from drf, not from django
Oh.. can we use drf validationerror in models ?
inchidi
Someone
I want to check the total before saving the data.. so i did in clean function of models.. any other way I can do in views/ serializers?