Questions tagged [django]
Django is a Python-based framework for creating web applications.
323 questions
25
votes
3
answers
899
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 ...
17
votes
2
answers
13k
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 ...
16
votes
1
answer
9k
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:
...
16
votes
0
answers
869
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 ...
15
votes
2
answers
285
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 ...
15
votes
1
answer
379
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 ...
14
votes
0
answers
968
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 by very amateur coders and I want everyone to be ...
13
votes
1
answer
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
2
answers
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:
...
11
votes
0
answers
3k
views
Sending notifications with Django channels
I have project on Django wich use Django Channels. I use Django Channel for sending notifications to users who are subscribed to articles changes (adding/editing/deleting comments on article).
So I'...
10
votes
2
answers
8k
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
1
answer
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
1
answer
198
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 ...
9
votes
2
answers
28k
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
1
answer
8k
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
1
answer
807
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 ...
8
votes
2
answers
476
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
2
answers
235
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
1
answer
3k
views
Django shopping cart, and testing
For an e-commerce web application I have written a shopping cart, and some tests for it.
I have used a course on Lynda.com, on building an e-commerce website, as inspiration on how to build the ...
8
votes
1
answer
115
views
Save 2 related models through a single form
Here are two models - Property and Developer:
...
7
votes
2
answers
132
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
2
answers
936
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 ...
7
votes
2
answers
4k
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?
...
7
votes
1
answer
6k
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
1
answer
153
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
1
answer
177
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
1
answer
78
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 ...
6
votes
2
answers
3k
views
Password generator in Django
I am a system admin, not a developer, so this might be pretty horrible code. This is a password generator. The point of the attempt was to become more familiar with Django at a lower level. I current ...
6
votes
1
answer
41k
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
2
answers
213
views
What are the latest Odds?
The main problem the following query is solving, is the following:
Each Offer has multiple Odds (...
6
votes
1
answer
645
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
1
answer
210
views
Get list of claims based on priorities
I have written the following function which works as expected but I still see there is some room for improving its readability
...
6
votes
1
answer
831
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
1
answer
153
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
1
answer
225
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.
...
6
votes
2
answers
121
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
1
answer
1k
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
1
answer
4k
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
1
answer
2k
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:
...
6
votes
0
answers
494
views
Xero API Client in Django
I'm not actually that new to writing Python. But I've no formal training and have only learnt to build applications to solve problems for my job out of necessity. Starting to bring my existing skills ...
5
votes
3
answers
418
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
2
answers
505
views
Converting an already-uploaded file and saving it to a model's FileField
Please review this:
...
5
votes
1
answer
484
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
2
answers
185
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
1
answer
161
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
1
answer
671
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
1
answer
134
views
Preventing code duplication in Django
I have these 2 functions that are almost the same:
...
5
votes
2
answers
215
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
2
answers
7k
views
Model design for Online Food order app
I have been trying to develop online food order application. I have taken the concept of zomato.com where a user or say owner registers his/her restaurant. After adding the restaurant, an executive ...
5
votes
1
answer
170
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?
...