Skip to content
Advertisement

Tag: django

How can I cast a DateField() + TimeField() to local time in a Django QuerySet?

My model as these fields: date = models.DateField() start_time = models.TimeField() end_time = models.TimeField() I would like to annotate the queryset with start_datetime and end_datetime, like so: However, the output field in the query results in a naive datetime: I would like the dates to be localized within the query. I tried wrapping the above expressions in django.db.models.functions.Cast(), with output_field=DateTimeField(),

Using regular expression for a field name in a Django

I have a model in Django that has the fields photo_1, photo_2, photo_3 and many other fields that does not contains the “photo” string on their names. Also, the photo fields can be blank, so I can find some rows with empty photo fields. For the html template, is there a way to go through the fields named “^photo_[0-9]*$” and

Why do I need to use SlugField in Django?

I searched on google and found this: “SlugField is a field for storing URL slugs in a relational database. SlugField is a column defined by the Django ORM. SlugField is actually defined within the django.db.” But still, the definition sounds a little complicated to me. I don’t even know what a slug is in this context and not sure about

Inherit choice class to extend it?

I have a field in my models.py that accepts choices determined in a class: The choice class is this: My doubt is how can I inherit this UserChoices class to another choice class, in order to extend it with another options. I tried the following: But it gives me a migration error: Obviously this example is simplified, the actual code

Django – issue with loading css

I’ve recently started learning Django and I’ve been having a lot of issues with implementing css into my code. I’ve found a lot of people with the same issue as me but I am still unable to find an answer. Currently when I run open the website it give me this https://imgur.com/a/0N23s7b And I’m not sure if this is because

Set iframe url to access pages in navigation bar in Django

I am new to Django framework. I am trying to use html pages in templates and get the interfaces. I got all of the pages one by one. Now I want them appear in an iframe. Here is my html code in homeAdmin.html page. And here is the views.py code that I have written for this problem. I am lack

Django – Get urls of all images that reference a Post?

I have this model where a Post can have many Photos. I’m trying to retrieve all posts, including ImageField url attribute (according to Django docs FileField and ImageField have a url attribute). So I’d like to ideally return all the urls of the images associated with the post (ideally in order of created). model.py view.py Answer Please do not use

Advertisement