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
Tag: django-orm
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
How to cache individual Django REST API POSTs for bulk_create?
I have a Django REST API endpoint. It receives a JSON payload eg. { “data” : [0,1,2,3] } This is decoded in a views.py function and generates a new database object like so (pseudo code): …
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
Getting the current date (and time) in Django
I was wondering what is the best way to get the current date in a django application. Currently I query the python datetime module – but since I need the date all over the place I thought maybe Django already has a buildin function for that. e.g. I want to filter objects created in the current year so I would
Convert Django Model object to dict with all of the fields intact
How does one convert a django Model object to a dict with all of its fields? All ideally includes foreign keys and fields with editable=False. Let me elaborate. Let’s say I have a django model like …