Tag Archives: django

Django: export object from database to excel

Questions: i have this in my template : <table> <tr><td>book_id</td><td>book name</td><td>book_author</td></tr> {% for book in books %} <tr><td>{{ book.book_id }}</td><td>{{ book.book_name }}</td><td>{{ book.book_author }}</td></tr> {% endfor %} </table> <a href=”/export”>Export to Excel !</a> my view seems to be like this: def export_excel(request): books = Book.objects.all() response = HttpResponse(books , content_type=’application/vnd.ms-excel;charset=utf-8′) response[‘Content-Disposition’] = ‘attachment; filename=”books.xls”‘ return… Read More »

How to export to excel datetime in Django 1.7

Questions: Iam using Django 1.7, Python 3.4 and PostgreSQL 9.1. I need to export to Excel some queryset. As a starting point I use this guide: outputting-excel-with-django In my model I have a field as a Datetime, and in utils.py I added already a style: (datetime.datetime, xlwt.easyxf(num_format_str=’DD/MM/YYYY HH:MM:SS’)), But when I try to export my… Read More »

Import data from excel spreadsheet to django model

Questions: I’m building a website that’ll have a django backend. I want to be able to serve the medical billing data from a database that django will have access to. However, all of the data we receive is in excel spreadsheets. So I’ve been looking for a way to get the data from a spreadsheet,… Read More »

Django Model Choices: IntegerField vs CharField

Questions: TL;DR: I have a table with millions of instances and I’m wondering how should I index it. I have a Django project that uses SQL Server as the database backend. After having a model with around 14 million instances in the Production environment, I realized that I was getting performance issues: class UserEvent(models.Model) A_EVENT… Read More »

Django with multiple databases and app specific routers, cannot add users in MSSQL

Questions: We have a Django application that is connecting to multiple MS SQL database instances. There is a router.py for each app that handles routing the processes to each database. This is my first time setting up multiple database access. Django built-in apps are routed to the default database via this router.py: class DjangoRouter(object): “””… Read More »

How do I run Django and PHP together on one Apache server?

Questions: I can currently run either Django through mod_wsgi or PHP on my Apache server. My Django projects run at: http://localhost and source is at C:/django_proj My PHP projects run at: http://php.localhost and source is at C:/web If I turn both on, php.localhost and localhost go to the Django project. I’ve already set them up… Read More »

How to use HTML5 color picker in Django admin

Questions: I’m trying to implement the HTML5 colorpicker in Django’s admin page. Here is my model: #model.py … class Category(models.Model): … color = models.CharField(max_length=7) Here is the form: #form.py from django.forms import ModelForm from django.forms.widgets import TextInput from .models import Category class CategoryForm(ModelForm): class Meta: model = Category fields = ‘__all__’ widgets = { ‘color’:… Read More »