Questions tagged [django]

Django is a Python-based framework for creating web applications.

Filter by
Sorted by
Tagged with
25
votes
3answers
832 views

Music info model

I'm learning Django as I go. I know this model is missing user authentication, registration, comments/comment threading, and voting. But this is my starting code for my model. What are some of the ...
16
votes
1answer
10k views

Django Rest Framework - ManyToMany relationship through intermediate model

I'm new to Django and have just started to learn the basics. I have some questions about how to structure the code, how relationships should be written, and where the business logic should live. I ...
15
votes
1answer
337 views

Modeling a Mage character from nWoD, using Django

Goal Design a representation of a mage character from the World of Darkness RPG, as well their associated spells. Here is a visual representation of the schema. You can see it more closely on ...
15
votes
0answers
7k views

Django Rest Framework - add/remove to a list

I have a model Collection which has a many to many relation to a model Item. I want to be able to add or remove items to this collection using Django Rest Framework. Option1 - make an action: ...
14
votes
2answers
242 views

Building Slack message

I have the function which builds and return Slack message with text and attachments. How can I refactor this function to make it ...
12
votes
1answer
4k views

Replacement for commit_on_success

I am porting an application from django 1.4.5 to django 1.6.1. I found that commit_on_success has been deprecated. Moreover I found specific incompatibilities when ...
11
votes
2answers
2k views

An idiom to use the same view function to create or edit an object?

Here is the skeleton of my (first!) Django app: ...
10
votes
1answer
7k views

Faster Django CSV generation for several million database entries

I am writing a CSV file generator that's filtering through about seven million database entries (MySQL backend). This part is especially slow and I was wondering if there is a way to make it much ...
10
votes
1answer
1k views

Python application to create Google Map image

I have written a Django app that would get some input and give you an image as output. The output image has 3 layers: Google Map image rosreestr (russian docs layer) data from geojson layer I hear ...
10
votes
1answer
168 views

Speed up my search

I have a django app with search powered by haystack. The general search goes very quickly, but I need to filter the results by their model type. It works but is very slow. I've never really worked ...
8
votes
2answers
18k views

Generating a unique ID for a filename

This function generates a unique id for my files, which will be stored in the database to reference them. It returns the id if unique, if not, it generates a new one. My separate file server can then ...
8
votes
1answer
4k views

CreateView set foreign key from URL parameter

I want to be able to create a lorum, using a ipsum_id (ForeignKey) that has been supplied in the URL. Using Django's class based views. Given the following URL: ...
8
votes
2answers
466 views

Django API Implementation

I am building a backend to a mobile application that will be hosted on a Django site connected to a PostgreSQL database. I have never built anything to accomplish this before and this is my first go ...
8
votes
2answers
219 views

How to DRY up my forms.py?

I have two ModelForms that are the same, except that one of them has its form layout built in a view and one has a submit button. These are pretty long and I have a ...
8
votes
1answer
97 views

Save 2 related models through a single form

Here are two models - Property and Developer: ...
8
votes
0answers
830 views

Django on virtual machine - watching changes in static files and autocompiling LESS without inotify

I'm setting up a Django development environment using Vagrant to run an Ubuntu virtual machine on VirtualBox. As this is a student project run mostly be very amateur coders and I want everyone to be ...
7
votes
2answers
124 views

Building SQL query

I wrote a messy function and I am wondering if you see any way I could clean it up. Essentially it takes in a list e_1=2&e_2=23&e_3=1 and makes a queryset ...
7
votes
1answer
5k views

Model classes for a quiz app in Django

I am creating simple quiz app in Django. It works, but I think that way I've done it is not the best. I have Exam detail view, which display questions related to that exam and answers for these ...
7
votes
1answer
143 views

School applicant form

I have created, in Django 1.6, a site for a school, where an applicant can get registered. It's a form that requests some information from the registrant and creates a random code for each applicant. ...
7
votes
1answer
129 views

TDD tests for every view and its permissions in a REST API

I am currently developing a Django Rest Framework API with TDD. I have 15 tests and counting for two views, which doesn't seem right to me. It takes me a lot of time to write the tests and a lot of ...
7
votes
1answer
154 views

Database modeling for products and store

I am planning to develop a virtual shopping mall where stores of any kind can be registered, such as in a physical shopping mall. First I want to develop an efficient and effective database modeling ...
7
votes
1answer
67 views

Finding the profile name for a join in my Facebook auth backend

I've written a project for handling various Facebook things and I ran into the issue where one project named the users profile Profile while normally they would be ...
7
votes
0answers
558 views

Let's register that Django user

Short intro So, I've been using Django for a while now and thought it would be nice to start a simple application. In an ideal World, each app must have a way of letting its users register and that's ...
6
votes
2answers
560 views

Implementation of lru_cache for daily “top categories” query

In my website, I want to show top categories by products' view / sell counts. Since this is not something changes every hour, I want to fetch real results only once a day from database (may be once a ...
6
votes
2answers
170 views

What are the latest Odds?

The main problem the following query is solving, is the following: Each Offer has multiple Odds (...
6
votes
1answer
32k views

Django query_set filtering in the template

Can I make my template syntax simpler? I'm hoping to eliminate the if and maybe also the for block. This worked in the shell ...
6
votes
1answer
625 views

Creating a pythonic snippet to read and clean .csv files

I am trying to import a .csv file, clean the contents, and make sure all the errors are eliminated. IO error file format error data error I am using the snippet below. Could someone help me clean ...
6
votes
1answer
705 views

Showing different forms for user type with Django/Python in views.py

I have 4 user account types, realtor, insurance broker, auto insurance agent, and mortgage broker. Each one of the users will have a different form for each to submit. I have the following in views.py ...
6
votes
1answer
126 views

Handling SMS replies to register/unregister phone numbers

I'm working on a Django Twilio app, and I believe it's coming along well. I just want to improve my code writing skills. How can I improve the below code? ...
6
votes
2answers
113 views

Django controller method to list the top characters, guilds, and killers

I've been reading the Chapter 8 of this book. Here's the view I'm currently coding. It list all characters/guilds according to the type of URL. ...
6
votes
1answer
582 views

Model structure for Player Team and Match in football application

I'm creating an application for foosball matches. I have models like below: ...
6
votes
1answer
3k views

Improving models for a Django quiz

I'm working on a little django quiz taking app. Currently I'm making it's models. So far I've got Quiz, Question, ...
6
votes
1answer
1k views

Django Rest Framework Totaling API values in different ways

I am working on a stats website for my softball teams that I manage/play for. Here is my current Stat model: ...
5
votes
3answers
404 views

Todo app for displaying a list of tasks

The main view in my (toy!) Todo app is, of course, to display the list of tasks. These are grouped by some criterion, and the tasks structure below is actually a ...
5
votes
2answers
2k views

Bank account model implementation in Django

There is a draft of my models.py. What can I do for code quality and readability increase? ...
5
votes
1answer
354 views

Python parser for attributes in a HAML template

I'm working on a feature for the HamlPy (Haml for Django) project: About Haml For those who don't know, Haml is an indentation-based markup language which compiles to HTML: ...
5
votes
2answers
162 views

Django model to do accounting for a Litecoin miner pool

I'm coming from Java so I am used to performing calculations I require in separate functions. I would like to know if the below code makes sense in my Django model especially the loop and calling ...
5
votes
1answer
120 views

Civil status database with Django

I'm beginning with Django and I have a Civil Status project. I created my first models.py in order to get a Form, but I had some advices in order to normalize my database. I made this process and I ...
5
votes
1answer
650 views

How would you rate this python code? (Django AJAX)

This code comes straight out from the example code in a Django book. I find it quite bad, mainly because the use of flags (if ajax then again ...
5
votes
1answer
97 views

Preventing code duplication in Django

I have these 2 functions that are almost the same: ...
5
votes
2answers
151 views

Test Driven Development with Django

I'm learning TDD with Django and currently I'm testing my CreateView class. I feel like I'm not using best practices but am not sure on how to improve my code. ...
5
votes
1answer
156 views

First attempt at weighted search

My concern is speed, since this may be used in an e-commerce website I want it to be as quick as possible. Where can I improve? ...
5
votes
1answer
102 views

NHL Stats web app

There is a web app. My first attempt to use NHL API have been reviewed here. I'm interested in any kind of refactoring of this code. But I have some questions that I want to point at specifically. ...
5
votes
2answers
1k views

Validation methods to ensure start and end date come after existing instances

We have a "Committee" class and I need to ensure that any new committee has start and end dates (don't know why they're CharFields instead of Dates or even Ints, but that's not my call) that are after ...
5
votes
2answers
2k views

Abstracting celery tasks with class based implementations

Background I want to send emails with a rendered template (django template, that is) but I also want to be able to control the QuerySets, and context provided. The goal is to make a task whose ...
5
votes
1answer
976 views

FIFO inventory allocation method

I am an owner of a small industrial business startup and I am learning to write software in order to efficiently keep track of our inventory and finances, as our needs have outgrown the capabilities ...
5
votes
1answer
151 views

Personal Project for managing Bookmarks - View Part

The code is the view part of my bookmarker - project for managing bookmarks by categories. It uses Python 3.4/Django 1.6. I have also included models.py for ...
5
votes
1answer
256 views

Raising an error for slug unique in django

I have the following model in models.py: ...
5
votes
1answer
1k views

LRU caching decorator that caches in the instance and in a shared cache

I needed a caching decorator, that could be used with methods and functions, that could take typed args and kwargs, and that was Python 2.7 compatible. Therefore I started with a backport of the <...
5
votes
1answer
636 views

Recursive Django filter to output a list from user hierarchy

I need to create an HTML unordered list (to display with jstree) to display the hierarchy of users, along with a list underneath the user's "subusers" of their comments. Each user could have many ...