Questions tagged [django]

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

Filter by
Sorted by
Tagged with
3 votes
3 answers
7k views

Storing values from checkboxes in database

I'm getting values from 2 checkboxes and save those values to a database. I don't like these if statements. How is it possible to simplify the code? ...
user152041's user avatar
3 votes
0 answers
5k views

Django 'Like' functionality for a post

I am implementing a like button for posts (Using a clustom Like model and the pre-defined User model from django.contrib.auth). Would appreciate hearing how I can improve this code. Also, I am ...
OhMad's user avatar
  • 133
2 votes
0 answers
972 views

Apply a series of functions on Django querysets using decorators

Let me first show my models : ...
Shikhar Chauhan's user avatar
3 votes
0 answers
2k views

Testing a Django password reset procedure

I am writing tests for the password reset flow. It involves emails, links to reset the password etc so I made a really long test. It is testing quite a lot of things. If I break up the tests then the ...
user avatar
1 vote
1 answer
82 views

JavaScript dynamic element filtering functionality

I am creating a Website with different boxes being displayed to the user, and he can filter them by their Status (the dates are stored on a Django database). The possible statuses are "Active", "...
OhMad's user avatar
  • 133
0 votes
1 answer
184 views

changing from function based view to class based view in Django [closed]

This is my attempt to convert my password reset function based view to a class based view. Please suggest improvements. This is my function based view ...
This's user avatar
  • 19
1 vote
0 answers
404 views

Django Rest Framework model relations for a Gallery app

I'm creating a school project, a Gallery app. I have the following entities: Profile, Album, ...
М.Б.'s user avatar
  • 111
1 vote
0 answers
237 views

efficient django model for resume

I am trying to create a resume app from django. I have divided the entities for resume as Resume, Experience, Education, Qualification/Skills, Reference. I have modeled the following entities as below ...
Priyanka's user avatar
  • 221
-4 votes
1 answer
564 views

Python - Performance of this code very slow [closed]

This is an excerpt of my html code ...
Srinivas's user avatar
4 votes
1 answer
245 views

Cleaning service API using Django REST framework

I am trying to write a cleaning service API using the Django REST framework, but I think how I defined this model is not robust enough for production and in turns will make any application using this ...
user149459's user avatar
1 vote
1 answer
65 views

script that imports only data that is not in the database yet

I want to write a script that imports data into a database (in django). The database has a Company class with a name (CharField) instance. Additionally, it has a Person class with name (CharField), ...
Tom's user avatar
  • 241
2 votes
1 answer
125 views

Validating and saving a user profile, using fat model vs. view code

I heard that fat models are good idea and I should avoid operations on database in my views so I do something like this below. Can you tell me if it's good idea and which version is better? Please ...
Florovit's user avatar
4 votes
1 answer
146 views

Django model design to analyse user activities on external websites

I am working on an app that analyses the activities of users on some external sites. The contents of the target sites fall into three types: Forum post: A user can either start a thread or reply to ...
eN_Joy's user avatar
  • 143
3 votes
1 answer
58 views

Ordering colors into a multidimensional list

The code below works fine but seems really hard coded and I feel like I over-complicated the way it should be, I have a list containing hex and non-hex colors. example : ...
Horai Nuri's user avatar
7 votes
1 answer
174 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 ...
Tushant's user avatar
  • 231
3 votes
0 answers
38 views

Django-Python Db-access optimization

Is is possible to make this function more efficient and possibly more readable? In addition, Am I doing this right? I mean, it works, but would it be better to do a complex query (with annotations) ...
VirtApp's user avatar
  • 131
1 vote
0 answers
519 views

Using 12-Factor Configuration Standard in a Python (Django) Project

I am currently learning practices from the 12-Factor guide using one of the Django apps that I am running in production. In short, after reading the theory and doing my best to understand the work ...
MadPhysicist's user avatar
0 votes
1 answer
339 views

Django query to find all items without a FK relationship except for excluded list

I have a Book model and an Author model that has a FK relationship to Book (I realize that ...
thumbtackthief's user avatar
3 votes
0 answers
173 views

Converting YouTube channels to podcasts

I created a Django app that converts YouTube channels to podcasts. It uses the actual YouTube paths for the URLs. The idea is that the user can just find the YouTube address of the desired channel (...
user avatar
1 vote
1 answer
26 views

DRY for rendering same header table for different content

I'm trying to make the following code DRY. The code outputs a table that shows violations. If there is any violation.status = resolved they go in separate table for ...
newdimension's user avatar
6 votes
1 answer
827 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 ...
jeffci's user avatar
  • 248
2 votes
1 answer
31 views

Scraping website for book listings, checking if database contains relevant listings, and displaying result in a Django view

This code works but is very slow. I am scraping a website for urls for various books, and then checking to see if we have complete records of those books in our database. After I process the URL to ...
thumbtackthief's user avatar
2 votes
1 answer
2k views

Speed up performance of nested for loops to get all related format of all Authors' Books

This works but is very slow. I have an Author table that foreign keys to all books by that author. Each book has a variety of formats it can appear in (html, pdf, etc), which its linked to by its ...
thumbtackthief's user avatar
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 ...
Denny's user avatar
  • 141
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 ...
Matt's user avatar
  • 311
5 votes
2 answers
3k 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 ...
thumbtackthief's user avatar
3 votes
1 answer
2k views

Django REST Framework - PDF Generator

I created a new endpoint for an API (Django REST Framework) that generates a PDF from an HTML template. I follow the example from the plugin django-easy-pdf. It's working, but I would like to improve ...
crazy_sec's user avatar
  • 131
2 votes
1 answer
307 views

Creating Docker network with REST API using Python Django

This solution is to create a docker network using Docker supported APIs. For achieving this, I am using Python and Django framework for providing RESTful APIs. ...
Here_2_learn's user avatar
4 votes
1 answer
1k views

Model classes for an expense tracking app in Django

I want to build a simple expense tracking app in Django. Each user can create categories, and each category can have multiple expenses: Additionally, I wanted to have a ...
Tom's user avatar
  • 241
8 votes
1 answer
7k 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: ...
Penguin Brian's user avatar
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: ...
Shak3nNotStur3d's user avatar
2 votes
1 answer
507 views

Authenticate users in Django

I'm writing a social networking site in Django. I created an account application which is part of site project. I implemented an authentication mechanism in the project. Every user has different ...
user avatar
5 votes
0 answers
572 views

Django blog application - views, urls, models, forms

I want to learn how to create websites and I have started learning Django web framework. I think Django is very good alternative for PHP and it isn't too complex as JEE. I'm very satisfied learning ...
user avatar
3 votes
1 answer
322 views

Set time zone from cookie

Is the set_cookie variable the correct way to signal that the cookie should be set? It does not seems pythonic to me: ...
user avatar
4 votes
1 answer
655 views

TDD Django - Shopping Cart

I'm new in Python TDD and I would like to ask you about some feedback for Django unit testing. ...
martinstastny's user avatar
6 votes
2 answers
877 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 ...
alioguzhan's user avatar
0 votes
3 answers
5k views

Button to dynamically clone a form field

I am very new to javascript and started with a very basic add button to my django app. Everything I found was using jQuery but for only one small script jQuery seems to be a too big overhead for me. ...
user avatar
2 votes
1 answer
218 views

customSignupForm code to allow signup for only the invited user

I am developing a feature where the user has to request for invitation if he/she wants to sign up on the site. When the request is accepted by the admin, the user gets to sign up, otherwise it shows ...
pythonBeginner's user avatar
2 votes
1 answer
10k views

Update model Django

How can I improve this? It's large and ugly. Any advice? I'm receiving a POST from a API, and I want to update only the fields that are not null. ...
Marcos Aguayo's user avatar
2 votes
1 answer
716 views

Simplify multiples request.GET.get and filter conditions with Django [closed]

I'm writting my Django website and I created a view function which let to filter data before filling my Django form. It works pretty well but I would find a way to simplify this function. It seems ...
Essex's user avatar
  • 293
3 votes
1 answer
53 views

Returning information about searches performed by a user

I have this simple piece of code from my django project. I feel that it isn't very well written. Maybe it possible to write this simple function in a better way? Maybe could you give me any advices ...
django11's user avatar
  • 131
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: ...
Robson's user avatar
  • 163
2 votes
1 answer
50 views

Is this "smart" way of populating the admin page ok code-wise?

I am currently hooking a large database up to a django site and want to populate the admin page with a number of models. I am using inspect to get a list of classes from each model file (one file per ...
arlyon's user avatar
  • 23
4 votes
0 answers
89 views

Duplicate vote checking

I am new to Django and added a vote duplicate check to the tutorial application. I set a cookie in the vote view: ...
user avatar
5 votes
2 answers
207 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. ...
intelis's user avatar
  • 171
4 votes
2 answers
9k views

Raise error when slug already exists

I looked into possible ways to raise an error to generate an error when a slug already exist. This is the model: ...
stetim94's user avatar
5 votes
1 answer
541 views

Raising an error for slug unique in django

I have the following model in models.py: ...
stetim94's user avatar
2 votes
0 answers
224 views

Django view for both AJAX and normal request

I'm starting with new project where there will be used to delete product using AJAX, but sometimes with normal request. What do you think about this view? I'm trying to make it as universal as ...
Milano's user avatar
  • 191
2 votes
0 answers
208 views

A Django EAV attempt

This seems to do the job of the EAV tables. Besides being EAV, is there room for improvement? Maybe there is something obvious, but how about indexing certain columns? ...
Simon's user avatar
  • 1,012
3 votes
2 answers
1k views

Unpacking tuple from Django's get_or_create function

Django's get_or_create function returns 2 values: the object and a boolean whether it was freshly created or not. I'm only really interested in the object it ...
Stupid.Fat.Cat's user avatar

1 2 3
4
5
7