Questions tagged [django]

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

Filter by
Sorted by
Tagged with
3
votes
0answers
3k 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 ...
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 ...
0
votes
1answer
74 views

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

This is my function based view ...
4
votes
0answers
615 views

Django Project for creating events

Before I continue developing this project, I just wanted to make sure I'm going about creating the views and tests in a "proper manner" or if I am completely fudging this up. Also, is it better to use ...
2
votes
0answers
699 views

Django Rest Framework ListAPIView - many if-s in get_queryset()

Please review my DRF ListAPIView code. There are a lot of if statements. I wonder if it's a good approach to put these if-s in <...
5
votes
2answers
163 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 ...
1
vote
0answers
3k views

Django model for an inventory management system

The usecase of my app I am trying to build is about Inventory Management System for a single company. I have attached a layout depicting what table or model should look like. I have designed the model ...
1
vote
0answers
68 views

Determine serializer on per-action basis for DjangoRestFramework ModelViewSet

I have a Profile object with two fields. One is safe for the public to see, while the other contains private data. ...
2
votes
0answers
627 views
3
votes
0answers
713 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 ...
1
vote
1answer
68 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", "...
1
vote
0answers
297 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, ...
1
vote
1answer
44 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), ...
1
vote
0answers
187 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 ...
-4
votes
1answer
399 views

Python - Performance of this code very slow [closed]

This is an excerpt of my html code ...
2
votes
1answer
118 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 ...
4
votes
1answer
114 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 ...
3
votes
1answer
1k 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 ...
3
votes
1answer
50 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 : ...
3
votes
0answers
36 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) ...
8
votes
0answers
837 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 ...
1
vote
0answers
404 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 ...
0
votes
1answer
172 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 ...
3
votes
0answers
146 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 (...
1
vote
1answer
25 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 ...
4
votes
1answer
484 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. ...
1
vote
0answers
53 views

Models for listing startup companies

I am learning Django and to hone my skills in Django, I want to create some product. I am thinking of developing a web app which is about registering the startup companies. I come from a developing ...
1
vote
0answers
47 views

Create Django objects on the fly. Better way to do it? And is the view the best place?

I have a model Sachbearbeiter that has a OneToOneField to the User model in ...
1
vote
0answers
32 views

Efficient backend for finding nearby properties

I am thinking of building an app based on location for finding nearby properties around 15 km from the location of the user. I am a beginner in Django and for such use case I could code the following ...
2
votes
1answer
27 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 ...
6
votes
1answer
728 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 ...
2
votes
1answer
1k 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 ...
3
votes
1answer
51 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 ...
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 ...
2
votes
1answer
259 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. ...
4
votes
1answer
628 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 ...
2
votes
1answer
528 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 ...
2
votes
3answers
218 views

Django view function

I have a view function that allows a user to Add / Edit / Delete an object. How does the following function look, and in what ways could I improve it? I was thinking about separating aspects of the ...
3
votes
1answer
182 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: ...
0
votes
3answers
4k 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. ...
6
votes
2answers
583 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 ...
2
votes
1answer
157 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 ...
2
votes
1answer
8k 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. ...
6
votes
1answer
622 views

Model structure for Player Team and Match in football application

I'm creating an application for foosball matches. I have models like below: ...
2
votes
1answer
44 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 ...
2
votes
0answers
219 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 ...
4
votes
0answers
80 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: ...
5
votes
2answers
157 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. ...
2
votes
2answers
6k 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: ...
5
votes
1answer
264 views

Raising an error for slug unique in django

I have the following model in models.py: ...