ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ
Can someone exactly explain difference and usages of onetoone field and foriegnkey field in django please?
onetoone is limited where as foreignkey is more versatile with what you can do. say a profile of a user is best kept as one to one as they wont have lots of profiles in a single instance. where as foreign key is better if you have more needs like say a artist having multiple albums is best for foreignkey or one to many or many to one. it goes both ways basically
Saman
Could u send your model? And let me say something about nested serialization in the put, patch, and post methods. These have a heavy structure for updating. So I really recommend using a rest-framework-generic-relation package, which is suggested by rest framework documentation. https://github.com/Ian-Foote/rest-framework-generic-relations This package handles the update and create, process for every update, and create methods
User model: class User(AbstractUser, TimeStampedModel): objects = CustomUserManager() email = models.EmailField(_("email address"), blank=True, null=True, unique=True) cell_number = PhoneNumberField(null=True, blank=True) national_id = models.CharField(max_length=11, null=True, blank=True) role = models.SmallIntegerField( choices=UserRoleChoices.choices, null=True, blank=True ) last_active_at = models.DateTimeField(null=True, blank=True) is_active = models.BooleanField(default=False) PersonInCharge model: class PersonInCharge(models.Model): entity = models.ForeignKey( Entity, on_delete=models.PROTECT, null=False, blank=False, related_name="person_in_charges", ) user = models.OneToOneField(User, on_delete=models.PROTECT) positions = ArrayField( models.SmallIntegerField(choices=PositionChoices.choices), null=True, blank=True )
Christian
django api: in a patch APIView class view: how can we get the pk of the object?
Nerd
django api: in a patch APIView class view: how can we get the pk of the object?
mostly it passing in the url so maybe example.com/id/ the you retrieve it as kwargs and implement in the patch logic
Rohan Ekke
I deploy my website on pythonanywhere my site is working well but i am not able to view images i.e media file, when i turn debug=false then i am getting 404 error and when its true then i can see image on that site
Hiccup
Hi, Everyone, I am new to here. Now, I am working with django backend project and I need to deploy my project using Github Action. Please help me.
ㅤ
hii, i was building a project where i need to "add more" fields button, for particular data field on a model,(i will take care of frontend, i'm confused on model and form, & i'm not into htmx) i'm little confused about how it going to save, and implementing it, please help me, if anyone knows, thanks in advance,
MUHAMMED
How to use django with Rabbitmq and celery for mailing
MUHAMMED
I set up everything but job is triggering. But function doesn't work
MUHAMMED
Function alone is working fine. I used sharedtask and called. It won't working
Mr. Achiever
Hello Team, I'm planning to create a web application similar to Udemy using Django. Can someone guide on how to start? I've already created multiple web apps using Django for day to day tasks. But this time planning for streaming videos using Django. Please suggest.
cj
Hello Team, I'm planning to create a web application similar to Udemy using Django. Can someone guide on how to start? I've already created multiple web apps using Django for day to day tasks. But this time planning for streaming videos using Django. Please suggest.
the other day you said you want to create something similar to YouTube, now similar to Udemy... what will you say tomorrow? You'd better start reading Django's documentation to learn how Django works, after that you can create whatever you want
Abdul
How install django in visual studio code bro
Rose
User Abdul has 1/3 warnings; be careful! Reason: flooding to draw attention
Charly
How install django in visual studio code bro
you don't install it on vs code, you install it according to the documentation
M. Hossein
In websocket, is it a wise idea to send an error message when user-sent websocket body has issues?
M. Hossein
Charly
Hmm. Why is that?
Why the user needs that some bad written code is beign used/
M. Hossein
Why the user needs that some bad written code is beign used/
So if websocket request is bad, simply is ignored?
Charly
Charly
not the developer
M. Hossein
I'm talking about the user
I would not show the error to the user. But I will send it as a message.
Charly
I would not show the error to the user. But I will send it as a message.
But the user will see an error which is impossible to him to solve?
M. Hossein
But the user will see an error which is impossible to him to solve?
No. Let's put it this way. You are sending a message to user X which does not exist. In frontend it's ignored. Probably the user is never going to use the websocket directly and the frontend framework is involved. But, it wouldn't hurt to inform developers that wanna use the websocket the detail of problem. Like 'Receiver user does not exist' or maybe 'message_body is required.' Wouldn't that make it easier to debug?
MUHAMMED
show what you have done
I am using windows based system. I have installed Erlang and then RabbitMQ. In the django app I have created a celery.py and added urls for RabbitMQon the settings. Then I have defined a function on django views with decorator @shared task. I have called this task using .delay option in One API. At that time in celery command prompt it gets reflected. Queue is updating. But function is not triggering I guess
Nasrullah
Is it possible to create objects for one class using another class modle?
Charly
Sagar
I have deployed django image upload project on railway.app , in the database it is showing the path of the image but In the admin panel when I try to open the image it is giving an error of path not found
ℳɾ.ℳơħάʍάđɾ૯zά
#settings.py MEDIA_ROOT = os.path.join(BASE_DIR, 'media') MEDIA_URL = '/media/' #----------------------------------------- #urls.py from django.conf import settings from django.conf.urls.static import static urlpatterns = [ # Your URL patterns ] + static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT)
Sagar
yes
Rose
User Soham has 1/3 warnings; be careful! Reason: this is neither a job board nor a bulletin board
☯️
Hello friends I have a Product model in my Django project, and I want to use product info’s in product list page and product detail page , and in product list page just need fields name , price , and photo , but in detail page need all info The question is : Is it better to write different serializers for both pages? And how should I name them? For example: ProductDetailSerializer? Or what about product list page and home page? Is there any pattern or rule to name them?
dr.Ibrahim
Hello everyone 👋 How can test local Django API on flutter application.
Mirco
Hello everyone 👋 How can test local Django API on flutter application.
Flutter app on a port, Django on another For example, flutter on 3000 and Django on 8000
Yan
Hello, I’m new to the Django framework and I have a problem. I created an application in the project and added the model. Now I can’t display the model data in an HTML page. Can you help me make the link?
João Pedro
Hi guys, how do you make authentications with django-ninja? Do you have any exemple?
nyctophile
Hi guys! i need your experience with the problem i am having I am trying to use Class based views in my project but having a problem with redirecting user to home page after trying to log in, here are my views https://hastebin.com/share/negoqapisi.xml i am getting this below : Method Not Allowed (POST): /main/home Method Not Allowed: /main/home [16/Feb/2024 19:23:19] "POST /main/home HTTP/1.1" 405 0 Not Found: /main/ Any help appreciated! Thanks
nyctophile
Show your urls
https://hastebin.com/share/olopatamip.lua here
Mirco
https://hastebin.com/share/olopatamip.lua here
Based on the error you are also pre-prending /main/ Where is it ?
nyctophile
Based on the error you are also pre-prending /main/ Where is it ?
from django.contrib import admin from django.urls import path,include from main import views urlpatterns = [ path('admin/', admin.site.urls), path('main/',include('main.urls')), ]
Mirco
https://hastebin.com/share/olopatamip.lua here
Add trailing slash to these urls and retry
nyctophile
nyctophile
how are you redirecting to the home page?
i tried override post, form_valid functions, and also tried from html like action={% url 'home' %}
Muflone
the error refers you're tring to do a post to the /main/home url
Muflone
check your browser console where are you redirecting
Ashkan
Hello my friends. Do you know how I should connect the host to the site?
Muflone
https://ibb.co/Jr2SWTJ here
the network section is empty, reload the page
Muflone
click on the home/ row and select the headers page
nyctophile
click on the home/ row and select the headers page
https://ibb.co/S52tfTX https://ibb.co/8rpvq5R here
Muflone
this is a POST request
nyctophile
this is a POST request
yeah i am getting this error when i submit username and password and i am not logging in
Muflone
yeah i am getting this error when i submit username and password and i am not logging in
your form is invalid, you're sending the form to the main/ page, not to the login page
Muflone
you mean my view, or forms.py?
your <form> where you created it, in the templates I suppose
nyctophile
your <form> where you created it, in the templates I suppose
<div> <form method="post", action="{% url 'home' %}"> {% csrf_token %} {{ form.as_p }} {# Renders all form fields as paragraphs #} <button type="submit">Create Group</button> </form> should i remove "action" ?
Muflone
(youtube is the worst thing available on internet to learn development)
Muflone
follow the official python tutorial or the djangogirls tutorial
Seth van Dalstein
Hi, I forgot my passwords to superuser and staff, the project is not yet published, but only in the process of development.