tagged [django]

Select distinct values from a table field

Select distinct values from a table field I'm struggling getting my head around the Django's ORM. What I want to do is get a list of distinct values within a field on my table .... the equivalent of o...

Rendering a template variable as HTML

Rendering a template variable as HTML I use the 'messages' interface to pass messages to user like this: I would like to include html in my `{{ message }}` variable and render it without escaping the ...

3 Oct at 17:11

Getting the SQL from a Django QuerySet

Getting the SQL from a Django QuerySet How do I get the SQL that Django will use on the database from a QuerySet object? I'm trying to debug some strange behavior, but I'm not sure what queries are go...

21 Apr at 23:10

How to remove all of the data in a table using Django

How to remove all of the data in a table using Django I have two questions: 1. How do I delete a table in Django? 2. How do I remove all the data in the table? This is my code, which is not successful...

4 May at 22:43

Different initial data for each form in a Django formset

Different initial data for each form in a Django formset Is it possible to prepopulate a formset with different data for each row? I'd like to put some information in hidden fields from a previous vie...

13 Dec at 21:9

How to give an "included" template additional context?

How to give an "included" template additional context? Is there possibility to narrow context for include. For example, I have "for" tag that gets from posts array - one post. Than I wonna put this po...

27 Jul at 14:36

How to drop all tables from the database with manage.py CLI in Django?

How to drop all tables from the database with manage.py CLI in Django? How can I drop all tables from a database using manage.py and command line? Is there any way to do that executing manage.py with ...

14 May at 09:33

Django - filtering on foreign key properties

Django - filtering on foreign key properties I'm trying to filter a table in Django based on the value of a particular field of a `ForeignKey`. For example, I have two models: I'd like to filter my

13 May at 21:13

How to revert the last migration?

How to revert the last migration? I've made a migration that added a new table and want to revert it and delete the migration, without creating a new migration. How do I do it? Is there a command to r...

10 Nov at 09:47

How to limit the maximum value of a numeric field in a Django model?

How to limit the maximum value of a numeric field in a Django model? Django has various numeric fields available for use in models, e.g. [DecimalField](http://docs.djangoproject.com/en/dev/ref/models/...

Django templates: If false?

Django templates: If false? How do I check if a variable is using Django template syntax? Doesn't seem to work. Note that I very specifically want to check if it has the Python value `False`. This var...

22 Nov at 17:46

Reference list item by index within Django template?

Reference list item by index within Django template? This may be simple, but I looked around and couldn't find an answer. What's the best way to reference a single item in a list from a Django templat...

20 Apr at 02:20

How can I change the default Django date template format?

How can I change the default Django date template format? I have dates in ISO 8601 format in the database, `%Y-%m-%d`. However, when the date is passed on to the template, it comes out as something li...

31 Jan at 14:44

What is the max size of 'max_length' in Django?

What is the max size of 'max_length' in Django? This is my model: But it can't run. What is the max size of the `max_length` parameter?

25 May at 09:40

How to do SELECT MAX in Django?

How to do SELECT MAX in Django? I have a list of objects how can I run a query to give the max value of a field: I'm using this code: rating is an integer

5 Sep at 19:33

How to concatenate strings in django templates?

How to concatenate strings in django templates? I want to concatenate a string in a Django template tag, like: Here `shop_name` is my variable and I want to concatenate this with rest of path. Suppose...

4 Jun at 05:54

Django Forms: if not valid, show form with error message

Django Forms: if not valid, show form with error message In Django forms, it can check whether the form is valid: But I'm missing what to do if it isn't valid? How do I return the form with the error ...

28 Nov at 20:28

How do I do an OR filter in a Django query?

How do I do an OR filter in a Django query? I want to be able to list the items that either a user has added (they are listed as the creator) or the item has been approved. So I basically need to sele...

16 Apr at 06:4

How can one get the set of all classes with reverse relationships for a model in Django?

How can one get the set of all classes with reverse relationships for a model in Django? Given: ``` from django.db import models class Food(models.Model): """Food, by name.""" name = models.CharFi...

How to 'bulk update' with Django?

How to 'bulk update' with Django? I'd like to update a table with Django - something like this in raw SQL: My first result is something like this - but that's nasty, isn't it? Is there a more elegant ...

30 Sep at 12:30

How to access a dictionary element in a Django template?

How to access a dictionary element in a Django template? I would like to print out the number of votes that each choice got. I have this code in a template: `votes` is just a dictionary while `choices...

21 Apr at 18:49

How can I get the file name from request.FILES?

How can I get the file name from request.FILES? How can I get the file name from request.FILES in Django? I tried using this

20 Aug at 21:4

Creating a dynamic choice field

Creating a dynamic choice field I'm having some trouble trying to understand how to create a dynamic choice field in django. I have a model set up something like: What I'm trying to

How do I perform query filtering in django templates

How do I perform query filtering in django templates I need to perform a filtered query from within a django template, to get a set of objects equivalent to python code within a view: In my template I...

8 Sep at 00:1

How do I make an auto increment integer field in Django?

How do I make an auto increment integer field in Django? I am making an `Order` model for a shopping cart and I need to make a field that auto increments when the order is made: How

29 Apr at 22:56