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
Tag: django-models
Use Serializer Method Field in another Method field
In my serializer, I have a method field, that I would want to use in another method field. This will be best explained in code: serializers.py models.py So I want users to see the first step of data analysis and then analyze the same data further. Is that possible? Maybe that is something I shouldn’t do? Answer I would use
How to add Two auto-generated field in one model in Django
I am in need to create two auto-generated fields: 1st field is ID and I am taking the position that is equivalent to id or we can say it is also an auto-generated field in the model. here is the code which I am integrating: please help me to solve this. Answer You can override the save method to set
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
TypeError: test_admin_login() missing 1 required positional argument: ‘self’
I’m writing test cases for my Django-based rest APIs. The problem is in the method of testcase class. I want to use test_admin_login method in the setuptestdata method. And I’m unable to do that. I’m getting error that I mentioned in the title. Answer if any function needs the self this means you need to create an instance of it
Access Django M2M values in queryset without looping
I receive some data through Ajax that allows me to do some filtering on a model that has some m2m relations (say Model). I get a queryset, say “content” that I then need to send back using json. Here are simplified lines of code: It was working fine but the project changed and I now need to include the values
Saving related model objects in single view
I am beginner and I am working on Django project – risk assessment application. I have a trouble to achieve saving on related objects for my application risk record. I am using MultiModelForm to achieve the following. I am successfully creating Whatif instance and connecting it with GuideWordi instance on save, however, I am not able to connect my RiskRecordi
How can I add the following JSON to a new URL based on its “category”: 2?
I have a JSON array in my server in Django rest framework, but I want to filter them by category , for example some of them have ‘category’:1 and some of them have ‘category’:2 like this: How can I add the following JSON to a new URL based on its “category”: 2? views: urls: Answer Assuming that this thingy you
How to append value to the ArrayField in Django with PostgreSQL?
I have created a model with the ArrayField in Django Model. I am using PostgreSQL for the database. I want to create new rows in the database or update the existing rows. But I can not insert or append data to the ArrayField. Model View The time field does not being created or updated with the new value. How can
A count of ForeignKey
I have class Team, which means a group of users. And the relation with User is One-to-Many. But Team may consist of 2 and N members. I think to write manually is not our way, because it depends on count of people which is always variable. How can I do it more elegant and rational? I mean to connect count