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
Tag: django-orm
Key (id)=() is still referenced from table for onetoone field
I have 1 to 1 field in my model where i would still need to link the data with other while i delete them on the other table.In my view i am deleting model 2 instance while that is deleted i am setting the completed to Tue but it is throwing error. models.py Answer There’s missing a default value or
How to Join Subqueries in Django ORM
I’m a beginner Django and I have been stuck on the following problem for a while. The basic thing I would like to achieve is that when client makes a GET list api request with a time period parameter (say 3 months) then the server would return an aggregation of the current 3 months data and also show an extra
Django: overwriting the method model of the abstract model, from inside the inherited models
I have a problem with re-assigning some var in my model, I have a model like this: but in the different models that used this abstract model, I need the use different expiration times in the exprie_time: so I am trying to overwrite this method in the model that was inherited from ExpireTime but it has no effect. so how
How to join linked models with foreign key?
I’m coming from Java and new to python / django. So may be my question is silly … I have one class Parent which contains an association with a class Child. Parent refers to its ‘Childs’ through the related name ‘children’. At Run time it works well, but at design time, it isn’t reachable from the declaration of the class
Custom field – got multiple values for keyword argument ‘related_name’
I’m working on a custom field that is just a shortcut to ForeignKey that points to addresses.Country model. When I run makemigrations it returns this error with I’m not sure: I understand that there are two to arguments passed but I don’t understand why. It looks like the field is initialized two times. Once with the kwargs I provided and
how to remove a newletter popup when someone sucscribes in django
when someone subscribes to the newsletter i automatically want to remove the popup for the user that just subscribed, i tried create a subscribed = False then change it to subscribed = True when a user subscribes. but it doesnt work. i can easily achieve this is a user is logged i, but in this case even unauthenticated users can
Field ‘id’ expected a number but got ‘Free’
i’m trying to add a form, so users can post thier own articles , but when i hit publish button it shwos Field ‘id’ expected a number but got ‘Free’. . i wasn’t adding the package_category field to the forms because i have set a default value for it in my models.py when i now add the package_category field to
How to cache individual Django REST API POSTs for bulk_create?
I have a Django REST API endpoint. It receives a JSON payload eg. This is decoded in a views.py function and generates a new database object like so (pseudo code): In tests, it is 20x faster to create a list of x1000 newobjs, then do a bulk create: So, the question is how to save individual POSTs somewhere in Django
Django group by Choice Field and COUNT Zeros
Consider the following django model: Now, I’d like to group all Ratings by the number of ratings per category like this: which returns a QuerySets like this: Is there a way to include all not-rated dimensions? To achieve an output like: Answer First we will create a dictionary with counts for all dimensions initialised to 0. Next we will query