Questions tagged [django]

81214 questions
1

votes
1

answer
338

Views

Conditions on django filter backend in django rest framework?

I am using Django filter backend on few fields which is working very good. But i want to filter fields when i get specific condition Like if user_type is basic get filter query otherwise get all objects from model. Mine code for filters is here: http_method_names = ['get'] serializer_class = SearchS...
Salman Ahmed
0

votes
0

answer
26

Views

Invalid syntax error in Django Model Class

I am creating my first model with Django. The codes in models.py is as below. from django.db import models Class Topic(models.Model): top_name = models.CharField(max_length=264,unique=True) def __str__(self): return self.top_name But I am getting a syntax error as below. Class Topic(models.Model):...
dinku33
5

votes
0

answer
137

Views

FactoryBoy - nested factories / max depth?

I am writing tests for a large Django application, as part of this process I am gradually creating factories for all models of the different apps within the Django project. However, I've run into some confusing behavior with FactoryBoy where it almost seems like SubFactories have an max depth beyond...
Jasper
1

votes
1

answer
7

Views

Crispy_forms_tags not fill form with instance in my update view

My problem about Update View On my UpdateView when I use {{form.as_p}} , Its work. But when I use {% load crispy_forms_tags %} Form not fill with instance. My View.py; def ayarlar (request): userinstance=get_object_or_404(kullaniciBilgileri,id=1) form = KullaniciForm(request.POST or None, instance...
Dany
1

votes
2

answer
1.4k

Views

Showing json field in Django admin

I have an Django model as follows: class BodyHeight(models.Model): seats = models.ForeignKey(to=Seats) name = models.CharField(max_length=127, null=True, blank=True) key = models.CharField(max_length=100, null=True) data = models.TextField(null=True, blank=True) class Meta: verbose_name_plural = 'Bo...
Boky
1

votes
2

answer
161

Views

Dropbox API with Django - Authentication

I'm trying to learn Dropbox API and want to use OAuth 2 for authorization. I'm getting following error: dropbox_auth_start() missing 1 required positional argument: 'request' Here is my code: Views.py from dropbox import DropboxOAuth2Flow from django.shortcuts import redirect def get_dropbox_auth_fl...
Hannan
1

votes
1

answer
182

Views

Django Tutorial part 2 Field Error

I got a field error when I was trying to run the tutorial of Django Part 2. I'm using Python 3.6 and Django 1.11. models.py import datetime from django.db import models from django.utils.encoding import python_2_unicode_compatible from django.utils import timezone class Question(models.Model): quest...
Karachay
1

votes
2

answer
1.2k

Views

DRF Object of type 'User' is not JSON serializable

I'm trying to return the details of the current logged in user in the following way: from .serializers import UserSerializer class UserDetailsView(RetrieveAPIView):...
Ishan Khare
1

votes
1

answer
678

Views

django create instant messaging

I'm building a django website and would like a to add an instant messaging feature to my userbase. What are some good ways to go about implementing this functionality? Does Channels and websockets have anything to do with this? Scratch that... so I'm looking at Django channels and it looks like a wa...
Micah Pearce
1

votes
1

answer
412

Views

Host Dockerized Django project on AWS

I have a Django project which is working fine on my local machine. I want to host the same on AWS, but confused on what service to use and what is the best practice to so. Do I use EC2, create a ubuntu instance on it and install Docker or use ECS ? What is the best practice to transfer my django pro...
ricky
1

votes
1

answer
1.9k

Views

how to create a autocomplete input field in a form using Django

I am pretty new to django and its ways. I am trying to create an autocomplete field for a form. My code is as below forms.py from django import forms class LeaveForm(forms.Form): leave_list = ( ('Casual Leave', 'Casual Leave'), ('Sick Leave', 'Sick Leave') ) from_email = forms.EmailField(required=Tr...
1

votes
1

answer
513

Views

How start start celery worker in Django project

I have a Django project with the directory structure mentioned below. I am trying to use Celery for running tasks in the background. I have facing some trouble while running the worker. Whenever I issue the following command, I get an error. Command $ celery -A tasks worker --loglevel=info From the...
arush1836
1

votes
3

answer
882

Views

Django-filters: multiple IDs in a single query string

Using django-filters, I see various solutions for how to submit multiple arguments of the same type in a single query string, for example for multiple IDs. They all suggest using a separate field that contains a comma-separated list of values, e.g.: http://example.com/api/cities?ids=1,2,3 Is there a...
mart1n
0

votes
1

answer
16

Views

Why select query returs data as tuple, i need associative array in python

I am new in python, I am working on models.py, I can see it shows me data as tuple, I need associate array, can anyone please help me for that, Here is my code for that, It shows me output this output ((1, 'What's up?', datetime.datetime(2019, 4, 19, 7, 38, 6, 449735)), i need field value data impor...
Nikul Panchal
0

votes
2

answer
9

Views

DeleteView not deleting

I have a problem in implementing DeleteView for a model that has a related model. When I try to delete a Task object nothing happens and it is not redirecting to the success_url. Noting happens. It just keeps on displaying the template. here are the models: class Project(models.Model): name = models...
dJudge
1

votes
1

answer
189

Views

filterset lookups for annotated fields

i have a problem to create a filterset for one of my ModelViewSets to provide filter functionality (incl. all allowed lookups e.g. in, gt, lt, ...) for annotated fields in my api. My Code looks as following: import rest_framework_filters as filters from django_filters.rest_framework import DjangoFil...
Smie85
1

votes
2

answer
441

Views

How To Edit ManyToManyField In Django Admin list Display Page?

I want to add Many2Many fields editable in Django admin list_display page. The model structure as below, class Genre(models.Model): name = models.CharField(max_length=250, unique=True) class Movie(models.Model): name = models.CharField(max_length=250) genre = models.ManyToManyField(Genre) And I tri...
1

votes
2

answer
278

Views

Django & React with django-webpack-loader vs Decoupled App structure linked to Rest API?

I am reading through the following tutorial: http://v1k45.com/blog/modern-django-part-1-setting-up-django-and-react/ I can't quite grasp what the added value is of using something like django-webpack-loader to fully integrate react.js and django when you can completely decouple django from react, ru...
Aran Freel
1

votes
2

answer
46

Views

Django Model: Find Avg by Grouping from models

I have been trying to find the avg for rating a get queryset. This is my models.py class Movie(models.Model): title = models.CharField(max_length=240) release = models.DateField(blank=True) review = models.TextField() user = models.ForeignKey(User, on_delete=models.CASCADE) poster = models.FileFiel...
Gokul
1

votes
3

answer
320

Views

how to exit “python manage.py runserver” in windows

How can I exit from the command line after executing: python manage.py run server 8080 I already tried Ctrl+C and Ctrl+Z but neither worked. Using gitbash instead of cmd changed nothing. I am using Windows (64 bit).
Jesse Luo
1

votes
2

answer
307

Views

Django Rest Framework DELETE returns no content in the body

I am using Django Rest Framework and I am making a DELETE request. As opposed to POST, PUT, PATCH, which all return the state of the object post creation/modification, delete does not return anything in the body (just the 204 code). Having this information would be helpful when trying to tie respon...
Andrei Cioara
1

votes
1

answer
215

Views

Django rest-auth Token authentication

I'm trying to use axios to get information from the /rest-auth/user/ page. This is my function: export const fetchUser = () => { const token = localStorage.getItem('token'); return dispatch => { dispatch(fetchUserPending()); axios.get('http://localhost:8000/api/v1/rest-auth/user/', {headers: { 'auth...
peter176
1

votes
2

answer
248

Views

Location for Django Rest framework exception handler

The DRF Docs say that once an exception handler is set up, it needs to be defined in the settings.py as follows: REST_FRAMEWORK = { 'EXCEPTION_HANDLER': 'my_project.my_app.utils.custom_exception_handler' } My Django project layout is like this: backend settings.py connectivity_service utils Custom40...
Amistad
1

votes
1

answer
1.1k

Views

django.core.exceptions.SuspiciousFileOperation: The joined path is located outside of the base path component

This worked fine everytime used to do django websites but this time it is giving me an error. Settings.py STATICFILES_DIRS = [ os.path.join(BASE_DIR, 'portfolio/static/') ] STATIC_ROOT = os.path.join(BASE_DIR , 'static') STATIC_URL = '/static/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media') MEDIA_URL...
Kiran Chavan
1

votes
3

answer
720

Views

Filtering on action decorator - Django Rest Framework

I am trying to filter data using a decorator action on Django Rest Framework, it works perfect if I use the global queryset (get_queryset() function) but I need to use it in a separate function. I am using django-filter to perform it. This is the code. My view: class ShippingAPI(viewsets.ModelViewSe...
Jeremias Enriquez
1

votes
1

answer
37

Views

Deleting a django model class object without foreignkey warning

I have two tables in MySql created with django models.One is Students model, other is Attendance model. class Attendance(BaseModel): stu = models.ForeignKey(Students, verbose_name=_('Student')) I did't put 'on_delete=models.PROTECT' to stu in Attendance class, because i need to able to delete a Stud...
ivbtar
0

votes
0

answer
6

Views

Django no such table after migrations

After trying all sort of migration im still getting this error I only get this error when trying to save the new object Traceback (most recent call last): File '', line 1, in File 'C:\Users\Carlos\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\base.py', line 741, in save...
Ventura
0

votes
1

answer
17

Views

AttributeError: 'module' object has no attribute 'home'

I've been following this guide on the first steps to setting up a website, but I'm getting an attributeerror when trying to launch the website in development mode. The link to the guide is: https://www.zeolearn.com/magazine/first-steps-to-create-the-website-with-django I've pasted the git bash outpu...
says
1

votes
2

answer
66

Views

No module named 'channels'

I am trying to install channels, following their tutorial(channels tutorial) but when I try to run the server I get the error: No module named 'channels'. I have tried reinstalling it, moving the app to the top of the list of 'INSTALLED_APPS' but it still does not work. I have installed python 3.7 a...
Arturo olmos
1

votes
2

answer
31

Views

Django Registering two different types of users with different fields

I want to create two users: patient and doctor. Both users will share some of the standard fields like first_name, last_name, etc. However, they should have different fields. Only the doctor, for example, will have fields like expertise and days_available. I reviewed a similar question but it doesn'...
Joseph Cheng
1

votes
1

answer
41

Views

Overriding a template in Django

I'm using this library to add a sessions tab on my django project. I'm calling the module's template from my project using this line: Sessions It works, but now I'd like to style the page, and to do that I need to override the module's template with my own template. So, as the module says here, I in...
Jack022
1

votes
1

answer
17

Views

Django testcase to test models failing

I am writing a test case for my model to test the __str__ but apparently it is failing. Here is my tests.py: from todoapp.models import User, Task from django.test import TestCase class UserModelTest(TestCase): def setUp(self): self.user = User.objects.create( first_name='john', last_name='doe', ema...
Vai
1

votes
2

answer
65

Views

Input search not working in Edge, IE, or Firefox

The search bar works in Chrome and Opera but not in the browsers named above. I suggest it has something to do with the onsearch='search(event)'. Mozilla say's its not supported and I was wondering if anyone knew of a solution to this issue? HTML:
Max Loyd
1

votes
1

answer
43

Views

How to retrieve Page content from streamfield in Wagtail CMS?

I've created SolutionPage and inside It's content field there is nested short_portfolio block. I've added several ProjectPage instances via Wagtail admin panel to PageChooserBlock. class SolutionPage(Page): ... content = StreamField([ ... ... ('short_portfolio', blocks.StructBlock([ ('title', bloc...
Tyler Durden
1

votes
2

answer
40

Views

is there a way to override model methods in django?

I have a model like this: class Car(models.Model): id = models.UUIDField(primary_key=True, default=uuid.uuid4) create_date = models.DateTimeField('date added', auto_now_add=True) modify_date = models.DateTimeField('date modified', auto_now=True) ... def last_tracked_location(self): ... try: url = '...
Tom
1

votes
1

answer
39

Views

Why my ajax function are not working on infinite scrolling?

I am building a webpage having infinite scroll using waypoints.js with backend as Django.The problem is, my jquery and ajax functions are not working on newly generated content while they are working with content on first page. **EDIT:-**I am updating my code so that it will be easier to undertsand...
Gagan
1

votes
1

answer
26

Views

Django foreign-key many to one relationship displaying on template

I'm trying to display job offers that are in relation ship with Company (Many To One) but I'm not able to do it. I've tried many loops but I'm not even getting queryset so I must doing it wrong but can't solve what I'm doing wrong. My files models.py class Company(models.Model): # field person with...
kabaneri
1

votes
2

answer
50

Views

Django signal based on the datetime field value

I'm struggling with the following. I'm trying to create a custom signal that will trigger when the current time will be equal to the value of my model's notify_on DateTimeField. Something like this: class Notification(models.Model): ... notify_on = models.DateTimeField() def send_email(*args, **kwar...
bloodwithmilk
1

votes
1

answer
50

Views

Django - a href duplicate target

I run into a weird issue in my first Django project. In my view I have a function that generates a link dynamically based on certain form values: return ' Some text' When I print the output in the console it shows the correct link in example: I return the result of the function in my view: return r...
Nico Müller
1

votes
1

answer
29

Views

How to limit the number of items displayed in Django app

I have this Django model in my newspaper app: class Article(models.Model): title = models.CharField(max_length=255) body = models.TextField() date = models.DateTimeField(auto_now_add=True) author = models.ForeignKey( get_user_model(), on_delete=models.CASCADE, ) def __str__(self): return self.title...
runnerpaul

View additional questions