Tridip
Hello guys, does anyone know how to create multiple user types in Django?? Suppose in an online doctor consultation app, I have two types of users for registering and login --- Doctors and patients. Can anyone help me with it?? Please. Thank You in advance
Bunty chhatri wala..
Hello guys, does anyone know how to create multiple user types in Django?? Suppose in an online doctor consultation app, I have two types of users for registering and login --- Doctors and patients. Can anyone help me with it?? Please. Thank You in advance
You can extend user model and add type_of_user field..which will have a choices field inside and default can be a patient. Eg: DOCTOR = 'DR' PATIENT = 'PT' type_of_user_choices= [ (DOCTOR, 'Doctor'), (PATIENT, 'Patient'), ] type_of_user = models.CharField( max_length=2, choices=type_of_user_choices, default=PATIENT) So.. When a person will register he can mention whether he's a dox or patient..
Bunty chhatri wala..
Okay thank you so much!! Then how to keep track of which type of user has logged in?? I mean since Django. Contrib.auth has for only one type of user
Read this. https://simpleisbetterthancomplex.com/tutorial/2018/01/18/how-to-implement-multiple-user-types-with-django.html
Mohammadreza
In any view you use you will have request.user which is an instance of AUTH_USER_MODEL
And that user is distinguishable with the help of type_of_user attribute that you set
Anonymous
in django rest framework mixins for createmodelmixin what is the request method? and what about for others
Anonymous
in django rest framework mixins for createmodelmixin what is the request method? and what about for others the method for retrieve and create view mixin create some confusion here
Mohammadreza
in django rest framework mixins for createmodelmixin what is the request method? and what about for others the method for retrieve and create view mixin create some confusion here
Main methods are post, get, delete, etc. And retrieve or create methods are called in them. e.g. post method is a method of generic api view and is overridden in create api view to call the create method that exists in create model mixin.
pythonista
I have seen a django security video that says "the django python code should be outside of the servers root. So that the python code is not accidentaly served as plain text." I have tried to access but I cant get the python as plain text. Or I am missing something. I want to fix this security problem and want to know about about this. Is this really a problem or not?
pythonista
What do you mean ?
"the django python code should be outside of the servers root. So that the python code is not accidentaly served as plain text." Is this true?
Jesus
how's called the programming technique(or design pattern) that django uses for the admin page? for example, having the admin page and loading it up with some models from each admin.p admin.site.register()
D
Which works best with django ?nginx or apache
D
What makes nginx better tan apache for Django
Gaurav
Hello, I am having some problems while implenting BaseDeleteView class. Error message says, object has no attribute render_to_response. Have a look to traceback-> pastebin.com/VeEELWZb
SmQ
I have seen a django security video that says "the django python code should be outside of the servers root. So that the python code is not accidentaly served as plain text." I have tried to access but I cant get the python as plain text. Or I am missing something. I want to fix this security problem and want to know about about this. Is this really a problem or not?
Usually the backend codes printed as plain text whenever the web server is not pointed to render the backend codes. So yes, it is true. Giving you an example, usually our website files are stored in public_html, so in order to implement your given method, just store all the the static files in public_html folder and store other files outside of public_html folder.
Tzipi
If this is the class definition: class Table1 (models.Model) pk=id class Table2 (models.Model) pk=id table1= FK table1 class Table3 (models.Model) feild1 = FK Table1 feild2 = FK Table2 num= int class Meta: unique_together =(“field1”,”feild2”) I want that class table2 will be created with a known table 1 pk. Many of table 2 to many of table 1, but for each record in table 2there is one and only 1 record in table 1. Table3 contain 2 FK to table1 and table2 and extra field. 1. Is table1 field is a m2m field or FK field? 2. I want to have option to add in Table3 many instances of {table1:table2}. In this implementation I am restricted, I think it because of unique constraint. 3. How I use the utility of : unique_together- in Table3 and through ? Do I have to have m2m?
Generalmax
Hello everyone! How do I render an image from the ImageField to HTML screen? I have created the model, and I have been able to upload from the admin page into my media fold. It returns error when rendering.i have set the MEDIA_ROOT and MEDIA_URL. I used the conventional rendering to render the input image, it returns error. I have also added the the static stuff to the URLPATTERNS
M.T.saeedi
Hi i install oauth2 in my application but not found in app install
M.T.saeedi
How can solve it?
pythonista
Why django gives error when i repeatedly press a button. How to prevent this?
a lee
hey im trying to create a pastebin clone i have some problems for self destructs here is my code for removing pastes after 1 minute class PasteCreate(CreateView): model = Paste fields = ['text', 'name', 'destroy'] def delete_old(self): now = datetime.datetime.now() ago = now - datetime.timedelta(minutes=1) old_pastes = Paste.objects.filter(created_on__lte=ago) if Paste.destroy == "True": old_pastes.delete() and its not working but i created a sub command with same code and set the time to 1 hour it works but it remove every post in db even the one i created 1 min ago any help or suggestions?
@l3j@ndr0
Hello I am new in django. This html tag syntax it is ok?? <img src="{% static 'images/img.jpg'%}>
cj
Hello I am new in django. This html tag syntax it is ok?? <img src="{% static 'images/img.jpg'%}>
yes, it's ok.... if you have any issue, you'd better show the full code and the traceback
Doragonsureiyā
The image does not show and exists in the image dir
Please provide a full explanation including all the details that you consider relevant. Your statement is too broad and there is no clear way to answer you, you have to explain: - what you're doing - what you're expecting - what you're using - where you're running the script - what Python version you're using - what packages and their versions you're using - and the most important thing: show the code YOU wrote (read rule 5️⃣ for that) and more details, that way your chances to get help will increase
Artyom
https://stackoverflow.com/questions/64304975/resize-uploaded-images-does-not-work-correctly-django Who can watch? Tell me how to make it work, my brain is already dead
B_Ayush
Guys...I am unable to sort out the error I am trying to get image from static folder and it is giving error Have a look on my code and directory
B_Ayush
<img href="{ % static 'templates\static\slide1.jfif' % }" class="d-block w-100" alt="..." />
Tridip
Hello guys, Needed one help. How to use Postman without using Django rest?? Please help. It's urgent Thank You in advance
Alex
hi, I am making a website and thinking of using django, but I am not sure weather it can handle asynchronous requests or nor..I searched on internet but didn't found any satisfying answers
Alex
help is appreciated
A
I'm trying to login using folowing code but even though I have already registered user with password this code is not working.always getting Invalid name/password.what's wrong in code ? data = JSONParser().parse(request) name = data.get('name', None) password = data.get('password', None) if not name or not password: return Response({'ERROR': 'Please provide both username and password'}, status=status.HTTP_400_BAD_REQUEST) if authenticate(username=name, password=password): user = User.objects.get(username=name) else: return Response({'Error': 'Invalid name/Password'}, status=status.HTTP_400_BAD_REQUEST)
Doragonsureiyā
To share code or error tracebacks please use an online pasting service, here is a list of suggested sites: - https://del.dog - https://dpaste.org - https://linkode.org - https://hastebin.com - https://bin.kv2.dev
B_Ayush
you have to set static folders in settings.py
I couldn't get the solution as .py file is language specific and static is folder here. If you are saying to keep the static folder and setiings.py file in same directory then I tried but couldn't even get result
Darth✧
https://dpaste.org/eWOD I m getting stuck while saving a file in model ...please have a look..any solutions how to do it ?
M
hi How many clients i can serve with just running manag.py runserver in Django .. i just read that people use ngnix and gunicorn for better experience
M
my project is small and mostly 6-10 users will login at a time.. will it survive without ngnix ?
Darth✧
What do u mean by " without using django rest?
Rohan
As far as I know ...u need a rest api for postman to test
You "can" use postman to test a rest api.
Rohan
Or you can use the django test suite which is easier and better.
Rohan
Yes
Why?
Rohan
Just why?
Darth✧
From view itself
Rohan
You have a database.
Darth✧
Just why?
I wanna use that processed data in other view or let say templ
Rohan
Even better, use a jsonfield and trasnform dataframe to a dictionary
Rohan
I wanna use that processed data in other view or let say templ
What do you think is more efficient to use in a template? Csv or a dictionary?
Darth✧
What do you think is more efficient to use in a template? Csv or a dictionary?
Definately json Bro I want to know ...how can I get the processed data for another view
Rohan
Like column by column and not csv as whole
Darth✧
Like column by column and not csv as whole
Yes I can also iterate every row but let say for huge data like 100k.....is it good to do like that ?
Rohan
If your data is huge, what you can do is store it on cloud and save a link of the uploaded data
Rohan
Like if you're using AWS. You can use S3.
Darth✧
Wait.... No
Thats why ...I want to convert it into CSv or any another format and save it as a file
Rohan
But it depends a lot on your usecase
Rohan
Would you frequently need that data?
Darth✧
Can u discuss in private ?
Rohan
Yup
Do you have to perform ops on that data? Like filters?
Rohan
Can u discuss in private ?
No. Let's do it here
Rohan
So we can have more input from others as well