Category: Django

How we can access and save object value of foregn model as default value, if the field is empty while saving the related object model?

Query asked by user class ObjectSEO(models.Model): object= models.ForeignKey(Objects, related_name=’seo’, on_delete=models.CASCADE) meta_description = models.CharField(max_length=170, help_text=”Please add product meta description, max length 170 characters”, default=”Some Texts” ) meta_keywords = models.CharField(max_length=250, help_text=”Please add product keywords separated with comma”, default=”Some Texts” ) meta_name = models.CharField(max_length=70, help_text=”object title” default = Objects.name) Here, I have two models, Objects and ObjectSEO. In […]

Dynamic inline CSS styling in Django template

Query asked by user I am new to Django and am trying to figure out how to use dynamic CSS that is only active for the current a user is on. I have a side nav with some categories and whichever the user is on should be active with the use of a class. This […]

PUT Request not Updating data-Django

Query asked by user So I am using Postman to get my request. My GET and POST appear to be working fine. It’s only when I go to update the data with PUT that its where I am running into the hiccup. Postman actually sends data back as if the object is being updated, but […]

Django can’t set attribute while changing media file url

Query asked by user I’m creating a function where I want the directory of the file changes if the image_type changes, for example if the image_type is aerial_view it should be in 1 folder and it if it is detailed_view it should move to another. The file is able to move succesfully, however I’m facing […]

0 value in Django PositiveIntegerField?

Query asked by user Can a field of type models.PositiveIntegerField contain a 0 value? I’m doing something like: points = models.PositiveIntegerField() Thanks, I know I should try it myself, but I haven’t a Django environment here. Answer we found from sources Yes, it can. It is debatable whether it should‚Äìthere is a longstanding bug report: […]

Render Form Elements Individually in Django

Query asked by user I’m trying to figure out how to render my form elements individually, since I think it’s the best way for my file as I have several parent CSS classes. I want to replace pretty much every label and input you see with my forms.py form models with keeping the CSS Styling. […]

Writing url in View in Django

Query asked by user I want to define a link for a character in the view. I used the following code, but it has an error. Error: Encountered unknown tag ‘url’ code: html=””” <p> <a href=”{% url index2 %}”>more information</a> </p> “”” I use the Folium library and want to put a link in the […]