I also need the field (commentGroupDesc) from the foreign keys objects. models.py views.py Here I get the commentGroup fine but I also need commentGroupDesc to put into my form. Answer At first, it’s not a good thing to name same your model field as model name which is commentGroup kindly change field name, and run migration commands. You can simply
Tag: django
Why is model._meta.get_fields() returning unexpected relationship column names, and can this be prevented?
Imagine I have some models as below: Now I have a function to return all column names to generate some overview in my HTML as such: Why does this return uptake_medium? As this is a ForeignKey relation set within the Uptake model, it should only be present within the Uptake model right? When I review the admin models this column
Updating values inside a python list
I want to update the price by using the function update_item. It fails at update_price = append(a[‘price’].data_2) Answer You can assign the value to the dictionary, with:
Django rest_framework : count objects and return value to serializer
i need to count all supporters in model and return value to serializer models.py serializers.py views.py Answer About your serializer file, beware of indentation, here is an example. As for counting objects, i believe you are looking for something like this: As specified in the queryset documentation. It is also possible to use the asynchronous version since Django version 4.1:
Django ORM How to query and get values when multiple conditions are fulfilled
I have following model and Product model is as I have the following sheet to calculate the min_days and max_days and insurance min max days. Insurance_period Travel days Value 1-92 days 1-30 days 30 1-183 days 1-90 days 45 1-365 days 1-90 days 50 1-365 days 1-180 days 60 My problem is suppose I have 29 days as travel days
How to add new site language in Django admin
I work on a project where we want to have multilingual site. We start with two languages defined in settings.py I am not the programmer doing the work but if I understood correctly all we need is to be able to add – for example – French language for the whole website but not via setting.py but Django admin web
How to give the data to serializer with JSONField
I have model and serializer with JSONField Then,I want to set the data to serializer class, However some how serializer.is_valid() faild. I have tested two pettern data1 data2 What data should I give to this serializer? And is there any method to debug is_valid()? Answer You are giving the data in right way, but as you are updating partially, you
PUT or PUSH for modifying the existing data?
I have viewset, Which shows the view on /api/companys There is a button for POST I can add the new data from this form. Now I want to modify the existing data. I have basic questions. PUSH can modify the data? or PUT should be implemented? How PUT can be implemented for ModelViewSet? Answer Mainly for updating(modify) data using PATCH
How can I connect to a locally hosted site within a docker container?
I’m trying to connect to a docker container’s locally hosted address. I’m using Django to serve a website within the container, and I want to connect to it on my local machine. How can I access this site from my local machine? I’ve tried to inspect the container and found that the local IP address is 172.28.0.4. Even after specifying
Get latest item date where item field_1 & item field_2 have duplicates
I’m using Django 4.0, and Python 3.8. I have a product that has a modification date, department name and designation. I want to retrieve each product but, for products that have the same designation and the same department, I only want to retrieve the last entry. Here is what i have now: I tried sorting on the result and removing