Django.fun

Questions & Answers about Django, page 3

03.12.2021
0
answers

I have a model with a many to many field. How can I display the information only if that field is selected?

I am making a recipe app. The model Recipe has a ManyToMany field favorites. On my favorites page I only want to display the recipes that are favorited. I can only figure out how to display all of the recipes. …

03.12.2021
2
answers

Why is my else statement not working in django rest framework?

I have the following code: views.py @api_view(['DELETE']) @authentication_classes([TokenAuthentication]) @permission_classes([IsAuthenticated]) def selected_job_delete(request,pk=None): if pk != None: job=Job.objects.get(pk=pk) jobdetail = Job_detail.objects.get(job=pk) jobtrack = Job_track.objects.get(job = pk) jr = Job_removed() jdr = Job_detail_removed() jtr = Job_track_removed() jr.jobname = job.jobname jr.owner = job.owner jr.enabled …

03.12.2021
1
answers

TransactionManagementError in Django when make migrate

I am new to programming , I have an issue when make migrate in Django 3.2.9. Here is my code, models.py from django.db import models from django.db.models.deletion import CASCADE, PROTECT # Create your models here. class Promotion(models.Model): description = models.CharField(max_length=255) …

03.12.2021
1
answers

How do I write a Django query to get distinct objects linked to another object?

I'm using Python 3.9 and Django 3.2. I have this class, which has a field for another ... class Transaction(models.Model): ... id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) account = models.ForeignKey('Account', on_delete=models.CASCADE) I woudl like to get the distinct set of …

03.12.2021
1
answers

Django - What happens when you delete an entity in a table that has a foreign key ManyToMany relationship to another?

I've noticed that Django doesn't let you set the on_delete parameter for ManyToManyField. This made me curious what happens if you delete an entity in a ManyToMany relationship? So for example, let's say we have Book, which has a ManyToMany …

03.12.2021
0
answers

Django-allauth: Redirect users post sign-up/sing-in to a specific page depending on the page they are coming from

Problem I have an invite system in my django app that allow users to invite other people (using their email) to join their team. When an invited user clicks on an invitation, they are redirected to an url that …

03.12.2021
0
answers

Fix Django "Unresolved attribute reference" for prefetched field

Let's say I have the following Django models: class Toolbox(models.Model): name = models.CharField(max_length=255) tools = models.ManyToManyField("Tool") class Tool(models.Model): class Size(models.TextChoices): SMALL = "S" MEDIUM = "M" LARGE = "L" name = models.CharField(max_length=255) size = models.CharField(max_length=10, choices=Size.choices) I have a …

03.12.2021
1
answers

In Django how I can create automatically a many to many entry based on a field found in two models

I have the following models example: class TestSet(models.Model): name = models.CharField(max_length=50) def __str__(self): return self.name class Class(models.Model): name = models.CharField(max_length=50) test_set_id = models.ForeignKey(TestSet) def __str__(self): return self.name class Test(models.Model): title = models.CharField(max_length=50) test_set_id = models.ForeignKey(TestSet) def __str__(self): return …

03.12.2021
0
answers

how to compare two querysets in django

I'm writing an if statement in Django that compares two querysets and extracts the same assignment. Although the results of cycle_per_day and next_visit_per_day are different, the field values ​​are the same because the same Class Model is used. The assignment_id …

03.12.2021
0
answers

Form not submitting to the DataBase when using HTMX

I have the following models, and as you can see they are related to each other class Leads(models.Model): project_id = models.BigAutoField(primary_key=True, serialize=False) created_at = models.DateTimeField(auto_now_add=True) expected_revenue = MoneyField(decimal_places=2,max_digits=14, default_currency='USD') expected_licenses = models.IntegerField() country = CountryField(blank_label='(select_country)') status = models.CharField(choices=[('Open', 'Open'), …

03.12.2021
0
answers

bad performance for loop with instance and bulk create

I need to use bulk_create to create a lot of "detalle"(details), the problem is i have to iterate trough a json to get the arguments, and i got 4 fk so django ask to me for the instance, not the …

03.12.2021
0
answers

django.core.exceptions.ImproperlyConfigured: SQLite 3.8.3 or later is required (found 3.7.17) for Python venv

I'm having trouble setting up my database on Django. I am running my server on CentOS7 and although I downloaded the version of SQLite I wanted to use, Python keeps pointing to the preinstalled version that is not compatible with …

03.12.2021
0
answers

Getting "Authentication credentials were not provided" error when I don't want to require authentication

I have a project with JWT authentication in Django Rest Framework. Usually I require user to be authenticated but in the case of GET action (both list and retrieve) I would like everyone to be able to access it with …

03.12.2021
0
answers

Django-allauth: My post-sign-up redirect flow with Google Auth is broken and I can't figure out why

I integrated django-allauth with my Django app but something is not fully working: Problem If a user that does not have an account in my DB tries to sign-up using the the google allauth process, after the authentication process …

03.12.2021
1
answers

Django Heroku Porting

Trying to set up Django configurations for a public url. So I ran this first. $ echo "web: python manage.py runserver 0.0.0.0:\$PORT" > Procfile $ git add Procfile $ git commit -m "Specify the command to run your project" …

03.12.2021
1
answers

Django FileField auto urlencoding problem

image_file = models.FileField(storage=s3, max_length=512, blank=True) I have a model with theis image_file field backed by s3 storage. The only problem I have with this field is if the filename contains any url-encode-able characters, it will auto encode the filename. …

03.12.2021
2
answers

Django cannot display model fields to template

I have a model from a package I would like to retreive fields from for the user to my template but am struggling to get this to work as I have done with user model previously: models class DeviceManager(models.Manager): def …

03.12.2021
1
answers

Python Requests with Django Rest Framework - 'detail': 'Authentication credentials were not provided'

I've got a tiny function that just looks to get a response from my DRF API Endpoint. My DRF settings look like this: "DEFAULT_AUTHENTICATION_CLASSES": [ # Enabling this it will require Django Session (Including CSRF) "rest_framework.authentication.SessionAuthentication" ], "DEFAULT_PERMISSION_CLASSES": [ …

02.12.2021
1
answers

Django Rest Framework API is being called twice

I am using Django Rest Framework to make a custom backend that does the web3 login flow. However, it is calling my authenticate function twice. And I can't figure out why. my token view: #expects public_address, nonce and token if …

02.12.2021
0
answers

How can I integrate jquery timepicker in my django project

Here is the jquery timepicker code: $('.timepicker').timepicker({ timeFormat: 'h:mm p', interval: 60, minTime: '10', maxTime: '6:00pm', defaultTime: '11', startTime: '10:00', dynamic: false, dropdown: true, scrollbar: true }); Here is my forms.py from django import forms from bootstrap_datepicker_plus import TimePickerInput …

1 2 3 4 5 638 639