Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
THE UPDATED RECORDS SEND TO EMAIL FOR DAILY 12CLK USING CELERY
need to create a cron task function to report that sends email to "jasper@bsetxt.com" the following number of new user created today number of user certificates created today this should execute everyday at 12 with celery -
Subquery django query to get biggest disctint values
So I have this query that I need to re-filter to get just the biggest taken_at field's value from distinct meter id, but I cannot get the django orm's/sql part to makes this query. <QuerySet [<Reading: [127] meter installation: 29, type: 1, taken: 2019-10-07 16:06:48.101453+00:00 value: 78.0000, comment: , VAT: 22.00>, <Reading: [126] meter installation: 41, type: 2, taken: 2019-10-07 14:05:32.415905+00:00 value: 7.0000, comment: asdfe, VAT: None>, <Reading: [125] meter installation: 41, type: 2, taken: 2019-10-07 14:02:37.588983+00:00 value: 7.0000, comment: asdfe, VAT: None>, <Reading: [124] meter installation: 49, type: 2, taken: 2019-10-07 12:19:49.067398+00:00 value: 8.0000, comment: , VAT: 2.00> this query contains lots of Reading objects, but I need to get just the biggest taken_at value from distinct meter installations, I've tried making annotation and then distinct , but they are not implemented together, I'm kinda new to SQL so any help would be great! reading.py class Reading(DateTrackedModel): meter_installation = models.ForeignKey( "MeterInstallation", on_delete=models.PROTECT, related_name="readings", null=False, blank=False, verbose_name=_("Meter Installation"), ) value = models.DecimalField( decimal_places=4, max_digits=10, null=False, blank=False, default=0, verbose_name=_("Value") ) price = models.DecimalField( decimal_places=4, max_digits=10, null=False, blank=False, default=0, verbose_name=_("Price") ) reading_type = models.ForeignKey( "MeterType", on_delete=models.PROTECT, null=False, blank=False, related_name="readings", verbose_name=_("Reading type"), ) comment = models.TextField(null=False, blank=True, verbose_name=_("Comment")) taken_at = models.DateTimeField(null=False, default=now, blank=False, … -
django register user not redirecting
I was trying to register a user. I followed some blogs and other steps but I was unable to redirect the user into a new page after clicking the register button and I also followed some answers but I was unable to find out the problem here. I am adding my code in the following, Html for form: {% block content %} <form method="post"> {% csrf_token %} {{ form.as_p }} <button class="btn btn-success btn-lg" type="submit">Register</button> </form> {% endblock %} <p style="margin: 10px;">If you already have an account , please <a href=""> <strong>login</strong> </a> </p> My views.py : Imports are: from django.contrib.auth.forms import UserCreationForm from django.contrib.auth import login, logout, authenticate Method for redirect: def homePage(request): if request.method == "post": form = UserCreationForm(request.POST) if form.is_valid(): user = form.save() login(request, user) return render(request,'index.html') else: for msg in form.error_messages: print(form.error_messages[msg]) form = UserCreationForm return render(request = request, template_name= 'home.html', context={ "form": form }) Urls.py: app_name = "main" urlpatterns = [ path('', views.homePage, name='home'), path('home/', views.home, name='home_url'), -
Django Admin "TypeError int() argument must be a string, a bytes-like object or a number, not 'Car'"
My project Admin worked fine, but since I've been working to link images to my model objects, it's raising this error. The specific error code is common when dealing with models, but none I've seen address the admin site in specific. So far, I've tried making a new migration with the new class, which went fine, and also deleting some admin fields. models.py Car model There's a lot I've skipped, but nothing I've changed since it was last working. class Car(models.Model): manufacturer = models.ForeignKey('Manufacturer', on_delete=models.SET_NULL, null=True) car_model = models.CharField('Model', max_length=50, null=True) description = models.TextField(max_length=4000) vin = models.CharField('VIN', max_length=17, help_text='Enter the 17 character VIN number.', blank=True, null=True) mileage = models.IntegerField(verbose_name='Mileage') car_images = models.ImageField(help_text='Upload pictures', upload_to=image_directory_path, storage=image_storage) date_added = models.DateTimeField(auto_now_add=True) engine_displacement = models.CharField(default=2.0, max_length=3, help_text="Engine displacement in Liters (E.g. 2.0, 4.2, 6.3)") price = models.IntegerField(default=0) seller = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True) id = models.UUIDField(primary_key=True, default=uuid.uuid4, help_text="Unique ID for this car") ... class Meta: ordering = ['date_added'] permissions = (("can_change_availability", "Mark car as sold"),) def __str__(self): return f'{self.manufacturer} {self.car_model}' def get_absolute_url(self): return reverse('showroom:car-detail', args=[str(self.pk)]) admin.py code @admin.register(Car) class CarAdmin(admin.ModelAdmin): list_display = ('manufacturer', 'model', 'model_year', 'mileage', 'status', 'date_added', 'price', 'seller') list_filter = ('manufacturer', 'status', 'transmission') fieldsets = ( ('General information', { 'fields': ('car_images', 'manufacturer', … -
Querying ManyToMany Relationship in Django
Suppose I have the following models, where Questions and Choices have a many-to-many relationship, and Choices and Voters have a many-to-many relationship. (To understand it better, consider a poll where each Question can have multiple Choices and each Choice can be associated to multiple Questions, and where each Choice stores a list of people who Voted for it, and Voters could have voted for multiple Choices.) class Question(models.Model): question_text = models.CharField(max_length=200) choices = models.ManyToManyField('Choice') class Choice(models.Model): choice_text = models.CharField(max_length=200) voters = models.ManyToManyField('Voter') def __str__(self): return self.choice_text class Voter(models.Model): name = models.CharField(max_length=500, default='FNU') def __str__(self): return self.name Given a Question object ques1, I want to be able to get a list of all Voters associated to the Choices for that question, i.e. I want a QuerySet of all Voters who voted for one or more of the Choices associated to the Question object ques1. Therefore if Choices c1 and c2 are associated to Question ques1, and Voters v1 and v2 voted for Choice c1 and Voter v3 voted for Choice c2, then running the query on Question ques1, I would want a QuerySet containing [v1, v2, v3]. Is there any query for this? The highly-inefficient workaround of course is to iterate … -
Dictionary key and string comparison in python
I compared the dictionary key with a predefined string, eventhough it looks similar, but the comparison always fails. for example: key='eng-101' and 'eng-101' string are not same. please help for key, value in course_dict.items() : print('search ky is --'+key) print('the elective courses are---',courses) #finding the key in string if(courses.find(key)==-1): print('key not found--'+key) else: print('---------------------the key found is---'+key) key=str(key +'-101,') key=key.replace(' ','') first_year_el_course+=key print(elective_counter) print(first_year_el_course) print('newly formatter key--: '+key) print(key=='eng-101') -
I made a responsive register with html and css, do I need made a register form in Django too?
Im using a nice responsive register for a website made with html and css. Im gonna use django for the administration part of my web, but the thing is, I need to make a register too in order to make the responsive register functional on my web? Im kinda stuck in this step. I'm asking the same for the login part! HTML: <!DOCTYPE html> <html lang="es"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <link href="https://fonts.googleapis.com/css?family=Manjari&display=swap" rel="stylesheet"> <link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous"> <link rel="stylesheet" href="reg.css"> <title>Document</title> </head> <body> <div class="back"></div> <div class="registration-form"> <header> <h1>Registrarse</h1> <p>Completa la información</p> </header> <form> <div class="input-section email-section"><input class="email" type="email" placeholder="Ingresa tu EMAIL aquí" autocomplete="off" /> <div class="animated-button"><span class="icon-paper-plane"><i class="fa fa-envelope-o"></i></span><span class="next-button email"><i class="fa fa-arrow-up"></i></span></div> </div> <div class="input-section password-section folded"><input class="password" type="password" placeholder="Ingresa tu CONTRASEÑA aquí" /> <div class="animated-button"><span class="icon-lock"><i class="fa fa-lock"></i></span><span class="next-button password"><i class="fa fa-arrow-up"></i></span></div> </div> <div class="input-section repeat-password-section folded"><input class="repeat-password" type="password" placeholder="Repita la CONTRASEÑA" /> <div class="animated-button"><span class="icon-repeat-lock"><i class="fa fa-lock"></i></span><span class="next-button repeat-password"><i class="fa fa-paper-plane"></i></span></div> </div> <div class="success"> <p>CUENTA CREADA</p> </div> </form> </div> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <script src="reg.js"></script> </body> </html> -
Hi, I am creating like button in django but problem is that i am trying to add some condition but it doesn't working properly can somebody help me
this is view of views.py file. if request.user.username == likes.user.username: is_liked = True else: is_liked = False context = { 'liked':is_liked } this is the condition for like button in html file. <form action="/post/id={{post.id}}" method='POST'> {% csrf_token %} {% if liked %} <button class="btn_like float-left text-center" type="button"><sup class="badge">{{post.like_set.all.count}}</sup><i class="fa fa-thumbs-o-up mr-2" style="font-size: 25px;font-weight: 100;color: royalblue" aria-hidden="true"></i></button> {% else %} <button class="btn_like float-left text-center" type="submit"><sup class="badge">{{post.like_set.all.count}}</sup><i class="fa fa-thumbs-o-up mr-2" style="font-size: 25px;font-weight: 100;" aria-hidden="true"></i></button> {% endif %} </form> this is my models.py. class Like(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE) posts = models.ForeignKey('Post', on_delete=models.CASCADE) Thanks in advance -
Model Form not displaying
I am using modelform for a model department is not working. (BTW,I have a custom user model also in users app of same project). All I am getting is a 'Test up' button in the html output. Also, Change E-mail and Signout are displaying may be consequence to usage of allauth in middleware. I don't know whether allauth is interfering with this or not (hope not).I have added department model to admin but there is some strange thing appearing in admin described below I have tried to debug with many ways. Here is the model from django.db import models from django.conf import settings from users.models import User,UserProfile # Create your models here. class department(models.Model): Dept_CHOICES = ( (1, 'Inventory'), (2, 'Dispatch'), ) dept_type = models.PositiveSmallIntegerField(choices=Dept_CHOICES,default=1,unique=False), HOD = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE,), Invest = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE,), def __str__(self): return self.dept_type Here is the view code def add_model(request): if request.method == "POST": form = departForm(request.POST) if form.is_valid(): model_instance = form.save(commit=False) model_instance.save() return redirect('/') else: form = departForm() return render(request, "test.html", {'form': form}) base.html <!-- templates/base.html --> <!DOCTYPE html> <html> <head> </head> <body> <main> {% block content %} {% endblock %} </main> </body> </html> test.html {% extends 'base.html' %} {% block content %} <div class … -
django : I need to find if similar products are in same company then update according to it
I have these two models , I need to update product furthur if two product or similar product in same company- class Product(models.Model): title = models.Charfield() company = models.ForeignKey(Company, models.DO_NOTHING) class Company(models.Model): title = models.CharFiled() -
Django: get_default of Charfield shows empty string
I have model field of CharField/TextField location = models.CharField(max_length=30, blank=True) Now i check the default value in Django shell [In}: User._meta.get_field('location').get_default() [Out]: '' I didnt mention any default value then how its setting to '' -
Having trouble getting django heroku to run properly. How do I resolve error code=H14 desc="No web processes running"?
I have previously ran this app on Heroku without issues. But it had been around 6 months since I deployed and I also switched computers from a Linux to a Windows machine. Now when I deploy, the deployment is successful but the service does not work. When I check the logs the error is: code=H14 desc="No web processes running" I have not changed the Procfile or the requirements.txt since it had been working requirements.txt: django gunicorn django-heroku requests djangorestframework django-cors-headers flask-sslify Procfile: release: python manage.py migrate web: gunicorn findtheirgifts.wsgi --log-file - wsgi.py """ WSGI config for findtheirgifts project. It exposes the WSGI callable as a module-level variable named ``application``. For more information on this file, see https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/ """ import os from django.core.wsgi import get_wsgi_application os.environ.setdefault("DJANGO_SETTINGS_MODULE", "findtheirgifts.settings") application = get_wsgi_application() I have tried some suggestions from similar threads heroku ps:restart heroku buildpacks:clear heroku ps:scale web=1 None of which seemed to change anything. Any help on this would be greatly appreciated! -
Django csrf token error only with uploading file
When update user profile model using model form in django: Raise csrf token missing or incorrect only with uploading file. In case of without file attached, I can update other fields. model.py file: class UserProfile(models.Model): user = models.OneToOneField(get_user_model(), on_delete=models.CASCADE) avatar = models.ImageField(upload_to='avatars', blank=True) first_name = models.CharField(blank=True, max_length=128) last_name = models.CharField(blank=True, max_length=128) birthday = models.DateField(blank=True, default='1990-12-01') town = models.CharField(blank=True, max_length=128) forms.py file: class UserProfileForm(forms.ModelForm): class Meta: model = UserProfile fields = ('avatar', 'first_name', 'last_name', 'birthday', 'town') in views.py file: @method_decorator(login_required, name='dispatch') class ProfileView(FormView): form_class = UserProfileForm template_name = 'profiles/profile.html' def dispatch(self, request, *args, **kwargs): self.username = kwargs.get('username') self.user = get_user_model().objects.get(username=self.username) self.userprofile = UserProfile.objects.get_or_create(user=self.user)[0] self.form = UserProfileForm({'first_name': self.userprofile.first_name, 'last_name': self.userprofile.last_name, 'avatar': self.userprofile.avatar, 'birthday': self.userprofile.birthday, 'town': self.userprofile.town) return super().dispatch(request, *args, **kwargs) def get_context_data(self, **kwargs): return {'userprofile': self.userprofile, 'selecteduser': self.user, 'form': self.form} def post(self, request, *args, **kwargs): return super().post(request, *args, **kwargs) def get_form(self, *args, **kwargs): return self.form_class(self.request.POST, self.request.FILES, instance=self.userprofile) def form_valid(self, form): form.save(commit=True) return redirect('profiles:profile', self.user.username) in profile.html file: <form method="post" action="." enctype="multipart/form-data"> {% csrf_token %} {{ form.non_field_errors }} {% for field in form %} <div class="form-group"> {{ field }} {{ field.errors }} </div> {% endfor %} <input type="submit" class="btn btn-primary" value="Update" /> </form> and software viersions: ubuntu 18.04 nginx 1.14.0 uwsgi 2.0.18 Django … -
Html content of Django application doesn't update after git pull and gunicorn restart
I'm running a Django website on Ubuntu 18.04. I have Nginx and Gunicorn running and website loading. I have initially installed it using git, and now as I'm trying to update it, something weird is happening. What I did: Pulled new code from git Made sure files are updated with nano Restarted Gunicorn (website still shows old html) Restarted server, then Nginx and Gunicorn (still old html) At this point I don't know where to check because all the files are new and it should have updated the website after restart. -
Ajax selected dropdown value and pass
I am trying to do following: user will select the value from the drop down menu, I would like to capture the data and pass to value to check if it exits and filter it. Using django view to fetch the media data files list. I would like to filter base on selected data site. VIEW @ajax_request def listofiles(request, *args, **kwargs): dir_name = "configurations" template_name = 'loadlistofiles.html' path = os.path.join(settings.MEDIA_ROOT, dir_name) filelist = [] context = {'file': filelist} for f in os.listdir(path): if f.endswith(".pdf"): # to avoid other files filelist.append("{}{}/{}".format(settings.MEDIA_URL, dir_name, f)) return render(request, template_name, {'file': filelist}) Above code will provide the list of all the files. I would like to filter it down using the dropdown select HTML AJAX <script> $(document).ready(function() { $("#files").submit(function() { // catch the form's submit event $.ajax({ url: 'loadlistofiles.html', type: $(this).attr('GET'), data: $(this).serialize(), // get the form data success: function(data) { // on success.. $("#fetchdata").html(data); // update the DIV } }); return false; }); }); </script> How to filter based on dropdown select value and check if the string in the file. For example: File name: dublin.aus1.pdf Dropdown will have a list like: AUS1, CH1, IND1 Like to check if the aus1 is in the … -
Use m2m_changed to modify original instance
When someone adds or removes an item from the additional_options field, I am catching that modification with the m2m_changed signal. If I wanted to use the data found in the m2m_changed signal to modify the original instance, how would I go about doing that? For example: class Topping(models.Model): name = models.CharField(max_length=100) class Pizza(models.Model): ingredients = models.CharField(max_length=100) toppings = models.ManyToManyField(Topping) def save(self, *args, **kwargs): super().save(*args, **kwargs) def update_data(sender, **kwargs): instance = kwargs['instance'] toppings = instance.toppings.all() for topping in toppings: instance.ingredients += f"{topping.name}, " print(instance.ingredients) # this will print the list of ingredients: "" instance.save() print(instance.ingredients) # this prints: "" and does not update the object in the admin m2m_changed.connect(update_data, sender=Pizza.toppings.through) In the example above, when instance.save() is called, the value in instance.ingredients reverts back to the default value. I believe this has something to do with the reverse parameter but I don't quite understand how to use it. -
Django Error: "ManyToOneRel object has no attribute verbose name"
I have a model named dashboard. Dashboard has a field called model_name which is the just a charfield. I have another field called Dashboard_Field which im trying to populate when the server initially starts. I do this by getting the dashboards and models. However I get the error "ManyToOneRel object has no attribute verbose name" for s_dashboard in dashboard: for models in model fields = model._meta.get_fields() for sfield in fields: if sdashboard.model_name == model._meta.verbose_name: field = Dashboard_Field.objects.create(field=sfield.verbose_name, dashboard=sdashboard) -
In the backend, can you access data from previous requests?
This is more of a theory question, so I'm not going to post any code. On the frontend, the user types in a search command. On the backend (Django in my case), it hits an API, the results of the search are saved into a Django View in views.py. On the frontend, the user interacts with this returned data and sends another request. On the backend, is the data from the first Django View still available for use? How do you access it? (The data is also in the frontend and I can send it with the second request. But if it's still stored on the backend then I wouldn't need to.) -
Error when making $http.post request "blocked by CORS policy"
Setup: I am running a webapp on DJango with AngularJS Situation: A peer has provided me an API link and I am trying to make a POST request through my webapp. I am currently running it through my app's angularjs controller and I get this error: Access to XMLHttpRequest at 'https://stage-xxxx.xxxx.com/api/po/createPO' from origin 'https://aggrisellshadow.aggrigator.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' Here is my Code - JS/Controller: $scope.sendAPI = function(){ console.log("sending API") var testData = { "gpo_number": "new Po", "plu_code": "123456712", "farmers_userId": "sujatha", "farmers_email": "sujatha@gmail.com", "delivery_date": "09/03/2019", "quantity_value": "100", "quantity_unit": "test Quan", "foodhub_userId": "sujatha", "foodhub_email": "sujatha@gmail.com" } $http.defaults.headers.post = { 'Content-Type': "application/json", 'tenant': 'XXXXXXapiTenent', "apikey": "XXXXXXX", "Access-Control-Allow-Credentials": true } $http.post("https://xxx.xxxx.xxxxx",testData,{data:JSON}) .success(function(data,status,headers){console.log("success")}) .error(function(data,status,headers){console.log("fail");console.log(data);console.log(headers);console.log(status)}) } Is this because I am trying to do this through my js and not through python? I can't seem to figure this out. Any help will be appreciated. Thank you ahead of time! -
Activate Virtual enviornment in Cpanel without SSH
I am deploying a django based web application. My hosting provider doesn't allow SSH access. So I deployed my application via python setup app. But it doesn't load static files altough it loads media files. so i wanted to execute "python manage.py collectstatic" But Only way to execute python command is through python setup app. But with the latest upgrade of Cpanel Python Setup Interface is fully different. I can't find a way to activate my virtualenv and execute command. #My Static configuration in Settings.py STATIC_URL = '/static/' STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'static') #My Urls.Py urlpatterns = [ path('admin/', admin.site.urls), ]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) #I also tried STATIC_URL = '/static/' STATIC_ROOT = '/home/user/public_html/static' This is the screenshot of Latest Cpanel. How to activate virtualenv and Execute Command. -
retrieving Django object returns AttributeError: module 'types' has no attribute 'StringTypes'
I'm attempting to migrate my apps from py2 to py3, and I'm running into this error when running migration scripts. After some digging, I get the same error when doing MyModel.objects.get(id=<some_id>) Now, I know StrginType is obsolete in python3 and I removed all basestring and replace with string in my scripts (not sure if related), but I'm not sure where this error is being triggered. I'm running Django 1.11 so it should be compatible. It seems to be it's something about Django but I can't figure out what. I searched on django doc and got nothing. Anyone got the same error before when retrieving an object through django? -
Django, how to get query with upper() in search
how to solve this, when i search with upper text dont show nothing.bellow my view def cerca(request): qs = Kompany.objects.filter(owner=request.user) name = request.GET.get('name') name = name.upper() # does work piva = request.GET.get('piva') if is_valid_queryparam(name): qs = qs.filter(name=name) if is_valid_queryparam(piva): qs = qs.filter(piva=piva) context = { 'kompany': qs, } return render(request, "inventary/kompany_list.html", context) -
Django cant be reached via parameterized url
Hello StackOverflow community, I'm currently learning how to use the library Django combined with Python. However, I've ran into some issues which are somehow strange. My situation is the following. I have a project called "animals" which is the base of the Django application. My app is called "polls". Then I've defined the following views. polls/views.py from django.shortcuts import render from django.http import HttpResponse def animals(request, animal_id): return HttpResponse("%s" % animal_id) def index(request): return HttpResponse('Hello world') So far, so good. Unfortunatly I can't say the same about the urlpatterns. polls/urls.py from django.urls import path from . import views urlpatterns = [ path('',views.index,name='index'), # Redirects to localhost:8000/polls/<animal_id> path('<int:animal_id>/',views.animals,name='animals') ] Whenever I want to navigate to the url "localhost:8000/polls/10/" Django reminds me of the fact, that the url is not accepted by the application and a 404 Error is thrown inside my browser. Am I missing something here? -
how can i use django form dropdown to my template?
i've created a form that has fields with dropdown, one for Countries and another one for Nationality but i do not know how to pass it to my html template. How can I solve this problem? i wrote my models and passed it to my form.py and use it into my template Models.py class User(models.Model): first_name = models.CharField(max_length=100) second_name = models.CharField(max_length=100) E_mail = models.EmailField(max_length=254) COUNTRY_CHOICES = [('saudi arabia +966','SAUDI ARABIA +966'), ('oman +968','OMAN +968'), ('kuwait +965','KWUAIT +965'), ('Qatar +948','QATAR +948')] country = models.CharField(max_length=250, choices=COUNTRY_CHOICES, null=True) phone = models.IntegerField(null=True) phone_code = models.IntegerField(null=True) birthday = models.DateField(null=True, blank=True) NATIONALITY_CHOICES = [('خليجي','خليجي'), ('ليس خليجي','ليس خليجي')] nationality = models.CharField(max_length=250, choices=NATIONALITY_CHOICES, null=True) def __str__(self): return self.first_name forms.py from django import forms from .models import User class UserForm(forms.ModelForm): class Meta: model = User fields = ('first_name', 'second_name', 'E_mail', 'country', 'phone', 'phone_code','birthday', 'nationality',) form_page.html <form action="{% url 'LandingPage:form_page' %}" method="POST" class="ui inverted form container"> {% csrf_token %} <div class="field"> <label>البريد الألكتروني</label> <input type="text" name="last-name" placeholder="joe@schmoe.com" {{form.E_mail}}> </div> <div class="ui field"> <label>أختر الدولة</label> <select name="gender" class="ui dropdown" id="select" {{form.country}}> <option value="">أختر الدولة</option> <option value="Saudi">Saudi Arabia +966</option> <option value="Qatar">Qatar +974</option> <option value="Oman">Oman +968</option> <option value="Kuwait">Kuwait +965</option> <option value="Bahrain">Bahrain +973</option> </select> </div> <!-- Mobile Number --> <div class="ui field"> <label>رقم الهاتف</label> … -
Django tests failing to run because they can't create table due to malformed foreign key
When attempting to run my tests, I get the error in the title. It does not tell me anything remotely useful about which table has failed to be created because the raw output of the error is: django.db.utils.OperationalError: (1005, 'Can\'t create table `test_pogo`.`#sql-269_231` (errno: 150 "Foreign key constraint is incorrectly formed")') #sql-269_231 gives me absolutely no information as to where I should go and check in my models to find the error, as it is not the name of any of my models or database tables. When running the project (not the testing modules) locally with my prod copy, everything seems to work as expected. How do I find and fix the broken model?