My rest api view defines only two methods: i have some experience overwriting the list, but i have no experience overwriting create as it seems to be a lot more complicated. What i want to achieve is following. My Request model has a special method which creates instance of Requests – start_request. This method creates not only the instance of
Tag: django
django framework: get value from django.db.models.fields.IntegerField
How can I get value from class django.db.models.fields.IntegerField? I want get 1 from admin field. This is python code: model class and function view A view function when I run user = Users.objects.get(id=userId) Answer I presume, you want the value of admin. From my understanding what you can do is you can use filter method on you object inside your
Django: Use makedirs in AWS S3
I have code that will automate CSVs and it will create a dir using makedirs with uuid dirname. The code is working on my local machine but not in S3. I am using an href to download the csv file by passing file_path in context. views.py def .. Thanks a lot! Answer For python and s3 you need to have
Accessing Parent Model from child element of ManyToManyField (Django)
I am having a models.py as follows So let’s say i have a comment Object Instance which’s id is 2 and raw content How to get parent post_id which contains this comment?? Answer Use related_name. Small change adding: related_name=’posts’: think of it like “if we start from the opposite side, what would be the name to use” (it’s always plural).
Saving centroid of a (multi)polygon as point geometry in a model
I have two tables, one with multipolygon geometries, the other with a column for point geometries. I want the centroid of the selected polygon to be saved as the point geometry for the other table. To add a new site, an existing administrative unit must be associated with it and the center of it’s polygon should be used as the
DRF: How to pass extra context data to serializers
I was searching the net and found the similar problem but it doesn’t work in my case, Idk why. I try to put some extra data to context in serializer, but get only 3 default fields: request, view and format and no mention for my custom data. My model: My Serializer: My ModelViewSet: I was debugging it through PyCharm and
Can’t handle two modelforms in a single submit/view flow with a FK relation?
I have the below two models In my template I render all fields except for start (which I don’t render at all) in the same <form></form> wrapper. Now in my view I want to create new instances for each of the modelforms but only if both are valid. This is what I have which throws NOT NULL constraint failed: planner_offer.applicant_id
How to inherent from a class that is already inherited from AbstractBaseUser in Django
I am trying to make an inheritance from a User class that is already inherited from the AbstractBaseUser but I am receiving an error that is telling me AUTH_USER_MODEL refers to model ‘authentication.User’ that has not been installed and I am sure I added the AUTH_USER_MODEL = ‘authentication.User’ in settings.py, I wonder how can I superpass this error and successfully
How to display the keys of a python dictionary as HTML table headers and values of each key as a row under that table header?
I’m currently working in a django project in which I do some data analysis using pandas library and want to display the data (which is converted into a dictionary) as a HTML table. dictionary that I want to display: I want to display the above dictionary like this table in django template. id product_name value available_qty 1 product1 200 1
If you see valid patterns in the file then the issue is probably caused by a circular import in django
I am getting this error “If you see valid patterns in the file then the issue is probably caused by a circular import in”. I saw other stack flow questions and I know the error is coming from views.py but I cannot seem to figure out where the error is views.py/myapp urls.py/myapp urls.py/myproject The above exception was the direct cause