Category "django"

Django. How to make ModelChoiceField work with SingleObjectMixin, FormView, and inlineformset_factory?

This shouldn't be hard How to show in a Django Model Form just the related records from Model.B for the user to choose. Ginven that it is provided the Model.A a

How to add two fields of django model and save the sum in another field?

class example(models.Model): var1 = models.IntegerField(default=0) var2 = models.IntegerField(default=0) var3 = models.IntegerField(default=0)

Django queryset by first letter?

For example my name is David and my friend is Daniel. I want to show these two names in their first letter wise . Item has a 'name' field. In the template I wan

Django Assigning or saving value to Foreign Key field

can any one help me with assigning value to a foreign key field. Im trying to create user profile where user can add there countries. when creating the models,

django.db.utils.IntegrityError: null value in column "id" violates not-null constraint

I want to save data from the Django model to PostgreSQL database with: mymodel.objects.create(title='test') this model only has title and id but it raises th

How to create a requirements.txt file in Django project?

I have been trying to create a requirements.txt file from the Pycharm terminal but it is adding all unnecessary packages as well. What should I do to show only

HTMX for messages from the backend in django

I wanted to use HTMX to show messages from django backend after a lot of trial and error I ended up with a working solution, that I want to leave behind for any

How do I add my html navbar into another html file in django

I am still very new to Django and I want to add the HTML for a navigation bar and its respective CSS into my base HTML file. Here is what I did up till now: in

Cannot run program "/../../python.exe" (in directory "/PythonSoftwareFoundation.Python.3.8_3.8.240.0_x64__qbz5n2kfra8p0"):Access is denied

I'm getting this error anytime when creating a new project in pycharm: Cannot run program "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.

Change renderer class inside custom pagination in django rest framework

I am using custom renderer class by default in settings.py. For api I check query parameter "page", if it exist then I paginate result else return normal respon

How do I add my html navbar into another html file in django

I am still very new to Django and I want to add the HTML for a navigation bar and its respective CSS into my base HTML file. Here is what I did up till now: in

Django - export excel make it faster with openpyxl

I am using Django restframework and I am trying to export excel. My issue is the process is take a lot of time till it generates the excel file. The final file

Django Google App Engine: 502 Bad Gateway, already installed package not recognized

I'm deploying Django in Google App Engine. I get 502 Bad Gateway and in the log I get the following error: 2021-03-08 12:08:18 default[20210308t130512] Traceb

How to add attributes to a Django form widget's media fields?

I can render media files for a django form, through a custom widget, like this: class TinyMCEWidget(Textarea): def __init__(self, attrs=None): if a

<link rel="stylesheet" type="text/css" href="{% static 'css/style.css' %}"> doesn't work

I link css to html on vs-code. center-aliend doesn't work here. Is there anyone who knows what part is wrong? I want to set the text 'Hello Static!!' to the cen

Why don't my CSS static files work in Django when I pass an optional parameter to the view?

I am making an application in Django, where I have a main (index) page displaying a number of objects styled with CSS. The CSS is in a static file. When I do no

Getting error while partial update data in drf

Hi Everyone i am creating api for partially update record, but getting error [patch() missing 1 required positional argument: 'id'], please help me out views.py

Django - Display in inline random info without relation to any model

Imagine there is a model: class OrgUnit(models.Model): name = models.CharField(...) type = models.CharField(...) address = models.TextField(...)

Styles not loading in Django

I have a site that needs some custom styles in Django and I can't get the static file to load. I have a static folder inside my main folder - The one where mana

Pushing a project with passwords in it

I created a django project and want to share it with my team members, however in the settings files it contains some passwords for the database etc. Of course w