Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
python3 django error imort name url
I am getting the "from core import urls as core_api_urls ImportError: cannot import name 'urls'" error when I run python3 manage.py runserver on ubuntu terminal. I use the following configuration: Python 3.5.2 Django 1.11.2 Please help me how I resolve this issue. -
What is a proper way to Override - Delete() method in Django Models?
I have an Employee model, and I don't want an objects of this Model to be deleted completely from DB. What I want is to keep them in DB even after 'deleting' them. I ended up building this solution, but it's confusing me a little bit: class EmployeeQuerySet(models.QuerySet): def delete(self): self.update( is_deleted=True, datetime_deleted=datetime.now() ) class Employee(models.Model): user = OneToOneField(User, on_delete=CASCADE) is_deleted = BooleanField(default=False) objects = EmployeeQuerySet().as_manager() def delete(self): # Should I use this: self.is_deleted = True super(Employee, self).delete() # Or this: self.is_deleted = True self.save() # Or this: self.update(is_deleted=True) I'm confused about having 2 delete methods, one in model and second in models.QuerySet. Can I accomplish what I want with just 1 delete method ? As I understood, delete() in models.QuerySet will be triggerred only if delete group of objects, and delete method in model will be triggerred only if I delete a single object, am I wrong ? How to accomplish what I want in a right way ? Thank you -
AssertionError: 404 != 200 in django test
When I test the simple app according to tutorial 'AssertionError: 404 != 200' is occured. Can anybody fix this problem? (Project name: simple_project, app name inside the project: pages) My app-level urls.py: from django.urls import path from . import views urlpatterns = [ path('', views.HomePageView.as_view(), name='home'), path('about/', views.AboutPageView.as_view(), name='about'), ] My app-level views.py: from django.views.generic import TemplateView class HomePageView(TemplateView): template_name = 'home.html' class AboutPageView(TemplateView): template_name = 'about.html' My project-level urls.py: from django.contrib import admin from django.urls import path, include urlpatterns = [ path('admin/', admin.site.urls), path('', include('pages.urls')), ] My tests.py: from django.test import SimpleTestCase class SimpleTests(SimpleTestCase): def test_home_page_status_code(self): response = self.client.get('/') self.assertEquals(response.status_code, 200) def test_abaout_page_status_code(self): response = self.client.get('about') self.assertEquals(response.status_code, 200) When I test, this error is occured: FAIL: test_abaout_page_status_code (pages.tests.SimpleTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "C:\Users\User\Dj\simple\pages\tests.py", line 10, in test_abaout_page_status_code self.assertEquals(response.status_code, 200) AssertionError: 404 != 200 -
django get the strange request while runserver
I am curious, I run the runserver with Django, the first request is what I am working on, but how about the others? I don't provide baidu server, why does someboy request it from my temporary server? [02/Feb/2018 12:20:05] "GET /stk/?format=json&_=1517542783567 HTTP/1.1" 200 2247 Invalid HTTP_HOST header: '1.164.39.192'. You may need to add u'1.164.39.192' to ALLOWED_HOSTS. [02/Feb/2018 12:50:54] "GET //wp-login.php HTTP/1.1" 400 62538 Invalid HTTP_HOST header: '1.164.39.192'. You may need to add u'1.164.39.192' to ALLOWED_HOSTS. [02/Feb/2018 12:51:20] "GET /wp//wp-login.php HTTP/1.1" 400 62571 Invalid HTTP_HOST header: 'www.baidu.com'. You may need to add u'www.baidu.com' to ALLOWED_HOSTS. [02/Feb/2018 14:15:00] "GET http://www.baidu.com/cache/global/img/gs.gif HTTP/1.1" 400 62677 -
Sqllite and Django shell are not in sync
I have deleted a table from sqllite3 shell and then when I try creating it again by running python manage.py migrate/python manage.py makemigrations table is not created and showing below error. How to re-create the table and make my db and the API is insync. I tried with the python manage.py dbsync also but not worked. Operations to perform: Apply all migrations: admin, auth, cgkapp, contenttypes, sessions Running migrations: Applying cgkapp.0002_delete_questions...Traceback (most recent call last): File "/home/shrivatsa555/.virtualenvs/django20/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute return self.cursor.execute(sql, params) File "/home/shrivatsa555/.virtualenvs/django20/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py", line 303, in execute return Database.Cursor.execute(self, query, params) sqlite3.OperationalError: no such table: cgkapp_questions The above exception was the direct cause of the following exception: Traceback (most recent call last): File "manage.py", line 22, in <module> execute_from_command_line(sys.argv) File "/home/shrivatsa555/.virtualenvs/django20/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line utility.execute() File "/home/shrivatsa555/.virtualenvs/django20/lib/python3.6/site-packages/django/core/management/__init__.py", line 365, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/home/shrivatsa555/.virtualenvs/django20/lib/python3.6/site-packages/django/core/management/base.py", line 288, in run_from_argv self.execute(*args, **cmd_options) File "/home/shrivatsa555/.virtualenvs/django20/lib/python3.6/site-packages/django/core/management/base.py", line 335, in execute output = self.handle(*args, **options) File "/home/shrivatsa555/.virtualenvs/django20/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 200, in handle fake_initial=fake_initial, File "/home/shrivatsa555/.virtualenvs/django20/lib/python3.6/site-packages/django/db/migrations/executor.py", line 117, in migrate state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial) File "/home/shrivatsa555/.virtualenvs/django20/lib/python3.6/site-packages/django/db/migrations/executor.py", line 147, in _migrate_all_forwards state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial) File "/home/shrivatsa555/.virtualenvs/django20/lib/python3.6/site-packages/django/db/migrations/executor.py", line 244, in apply_migration state = migration.apply(state, schema_editor) File "/home/shrivatsa555/.virtualenvs/django20/lib/python3.6/site-packages/django/db/migrations/migration.py", line 122, … -
Find the PYTHONPATH/env bitnami uses and how to use it
I've setup the one-click install of bitnami on Google Cloud. It's got Django 2.0 installed and that only works with python 3.x shown when I get out of a virtualenv I've created (djangoenv) bitnami@britecore-vm:/home/muiruri_samuel/apps/django$ cd .. (djangoenv) bitnami@britecore-vm:/home/muiruri_samuel/apps$ deactivate bitnami@britecore-vm:/home/muiruri_samuel/apps$ . /opt/bitnami/scripts/setenv.sh bitnami@britecore-vm:/home/muiruri_samuel/apps$ python -v # installing zipimport hook import zipimport # builtin # installed zipimport hook ImportError: No module named site # clear __builtin__._ # clear sys.path # clear sys.argv # clear sys.ps1 # clear sys.ps2 # clear sys.exitfunc # clear sys.exc_type # clear sys.exc_value # clear sys.exc_traceback # clear sys.last_type # clear sys.last_value # clear sys.last_traceback # clear sys.path_hooks # clear sys.path_importer_cache # clear sys.meta_path # clear sys.flags # clear sys.float_info # restore sys.stdin # restore sys.stdout # restore sys.stderr # cleanup __main__ # cleanup[1] zipimport # cleanup[1] signal # cleanup[1] exceptions # cleanup[1] _warnings # cleanup sys # cleanup __builtin__ # cleanup ints: 5 unfreed ints # cleanup floats bitnami@britecore-vm:/home/muiruri_samuel/apps$ python ImportError: No module named site I tried a snippet I saw on bitnami community on starting the env but it didn't work. I need to pip install a new package to where bitnami has it's packages so it can use it. I'm ok with just running … -
Django URL give me space between root and included urls
So I create an url in root/project/urls.py with this lines from django.conf.urls import include from django.contrib import admin from django.urls import path urlpatterns = [ path('admin/', admin.site.urls), path('users/', include('accounts.urls')) ] while in my root/app/urls.py from django.urls import path from .views import UserView, AuthenticationView urlpatterns = [ path('register/', UserView.as_view()), path('auth/', AuthenticationView.as_view()), ] So it is expected to give me http://localhost:8000/users/register and http://localhost:8000/users/auth urls. Meanwhile my request doesn't behave as expected. apparently it returns me a space between the root path and include path. I check my root/project/settings.py file I don't find any weird settings. Does anybody know what is going on? -
Django 2.0 DateTimeField add by admin failure
This is pretty specific: I have a dead simple model. from django.db import models class Update(models.Model): update = models.DateTimeField() When I try to add an update in the admin panel, it foobars the whole thing, and gives me an error immediately saying: 'datetime.date' object has no attribute 'tzinfo' Any ideas? this has to be a bug no? Django 2.0.1, Python 3.5.4. -
Check if a form exists or is rendered in Template. Django
I have a situation where I display a Form sometimes and sometimes I don't display it. Actually, there are multiple forms using the same Submit button. What do I do to take care of the situation when a particular form is not shown in the template. The template code {% extends BASE_TEMPLATE %} {% load crispy_forms_tags %} {% block title %}<h2>New Thread</h2>{% endblock %} {% block content %} <div class="col-md-6"> <form method="post" accept-charset="utf-8">{% csrf_token %} {{ threadForm|crispy }} {{ postForm|crispy }} {% if SHOW_WIKI %} {{ wikiFrom|crispy }} {% endif %} <input type="submit" class="btn btn-primary btn-sm" value="Submit"/> </form> </div> {% endblock %} This is the view code @login_required def createThread(request, topic_title=None): if topic_title: try: if request.method == 'POST': topic = Topic.getTopic(topic_title) threadForm = ThreadSUForm(request.POST, prefix='thread') postForm = PostForm(request.POST, prefix='post') show_wiki = getattr(settings, "REFORUMIT_ALLOW_WIKI_FOR_THREADS", False) and topic.is_wiki_allowed wikiForm = WikiCreateForm(request.POST, prefix='wiki') if threadForm.is_valid() and postForm.is_valid() and wikiForm.is_valid(): thread = threadForm.save(commit=False) post = postForm.save(commit=False) wiki = wikiForm.save(commit=False) thread.op = post thread.wiki_revision = None post.setMeta(request) wiki.setMeta(request) if is_authenticated(request): post.created_by = request.user wiki.author = request.user thread.save() wiki.wiki_for = thread wiki.save() post.save() thread.wiki_revision = wiki thread.save() return HttpResponseRedirect(thread.get_absolute_url) else: topic = Topic.getTopic(topic_title) threadForm = ThreadSUForm(prefix='thread', initial={"topic": topic}) postForm = PostForm(prefix='post') wikiForm = WikiCreateForm(prefix='wiki') show_wiki = … -
Django celery with twilio SMS
I have my twilio client object inside tools.py and celery tasks inside tasks.py. I have to import the twilio connection object inside celery tasks. tools.py from django.conf import settings from twilio.rest import Client client = Client(settings.TWILIO_SID, settings.TWILIO_TOKEN) tasks.py from .tools import client from config.celery import app @app.task def send_sms(): client.messages.create(...) return 0 If I import the client like this my celery tasks are not registered. celery -A config worker --loglevel=info but If I remove the client import the tasks are working fine. What could be the issue ? and how can I import the client object ? Thanks. -
Duplicate -tpl.c~ files when created a new project in Django
I created a new project with django-admin startproject basicform And then created a new application django-admin startapp basicapp But, when i started my server, python manage.py runserver It made duplicated files, like this https://drive.google.com/open?id=1MTvpHf7pACsp9o_b129g5wPsKqwbbZDp Is this an ERROR? Should i delete the files? I am working on django-1.11 and Python 3.6.4 :: Anaconda, Inc. Also, when i tried running the server, it worked fine. python manage.py runserver https://drive.google.com/open?id=1arjf3U8Mm8ggwLTbSk5Gc9bd_FDl5lJj -
Need to sort dict values and print highest value pair using Django Python
As i am using Python for backend and Django for frontend. Currently i am getting output in background as below from function: d={'Testcase1': {'hydra.c': 10,'clone.c':5}, 'Testcase2':{'hydra.c':337,'vendor.c':100 }, 'Testcase3':{'hydra.c':100,'vendor.c':80} 'Testcase4':{'vendor.c':89,'template.c':98,'temp.c':92}, 'Testcase5':{'vendor.c':83} 'Testcase6':{'template.c':34}....} for key,values in d.iteritems(): so=sorted(values.iteritems(),key=operator.itemgetter(1)) print(key,so[-1][0],so[-1][1]) for backend i'm getting correct output but how to implement this function in Django frontend {% for key,value in d.items() %} {% for k,v in sorted(value.iteritems(), key=lambda (k,v): (v,k)): <table> <tr> <td>{{ key }}</td> <td>{{ k[-1] }}</td> <td>{{ v[-1] }}</td> </tr> </table> -
How to add CSS class to django RadioSelect label?
how do i add css class for the auto generated label for a RadioSelect widget <div> {% for rdo in form.category_res %} <div class="custom-control custom-radio custom-control-inline"> {{ rdo }} </div> {% endfor %} </div> -
The view users.views.RegisterView didn't return an HttpResponse object. It returned None instead
I am using this code for a register form. But the post request doesn't work and give me an error : ValueError at /register/ The view users.views.RegisterView didn't return an HttpResponse object. It returned None instead. views.py class RegisterView(View): def get(self,request): register_form = RegisterForm() return render(request, 'register.html',{'register_form':register_form}) def post(self,request): register_form = RegisterForm(request.POST) if register_form.is_valid(): user_name = request.POST.get("email", "") user_psw = request.POST.get("password", "") user_profile=UserProfile() user_profile.username = user_name user_profile.email = user_name user_profile.password=make_password(user_psw) user_profile.save() send_register_email(user_name,"register") pass urls.py from django.contrib import admin from django.urls import path, include from django.views.generic import TemplateView import xadmin from users.views import LoginView , RegisterView import xadmin urlpatterns = [ path('xadmin/', xadmin.site.urls), path('',TemplateView.as_view(template_name="index.html"),name="index"), path('login/',LoginView.as_view(),name="login"), path('register/',RegisterView.as_view(),name="register"), path("captcha/", include('captcha.urls')) ] forms.py class RegisterForm(forms.Form): email = forms.EmailField(required=True) password = forms.CharField(required=True, min_length=5) captcha = CaptchaField(error_messages={"invalid":"please input correctly"}) register.html <div class="tab-form"> <form id="email_register_form" method="post" action="{% url 'register' %}" autocomplete="off"> <input type='hidden' name='csrfmiddlewaretoken' value='gTZljXgnpvxn0fKZ1XkWrM1PrCGSjiCZ' /> <div class="form-group marb20 "> <label>邮&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;箱</label> <input type="text" id="id_email" name="email" value="None" placeholder="请输入您的邮箱地址" /> </div> <div class="form-group marb8 "> <label>密&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;码</label> <input type="password" id="id_password" name="password" value="None" placeholder="请输入6-20位非中文字符密码" /> </div> <div class="form-group marb8 captcha1 "> <label>验&nbsp;证&nbsp;码</label> {{ register_form.captcha }} <img src="/captcha/image/2f3f82e5f7a054bf5caa93b9b0bb6cc308fb7011/" alt="captcha" class="captcha" /> <input id="id_captcha_0" name="captcha_0" type="hidden" value="2f3f82e5f7a054bf5caa93b9b0bb6cc308fb7011" /> <input autocomplete="off" id="id_captcha_1" name="captcha_1" type="text" /> </div> <div class="error btns" id="jsEmailTips"></div> <div class="auto-box marb8"> </div> … -
Django if function in html to set changes in selected option tag
when I use the django if function in the html template to set changes to the selected option tag, but nothing changes <form method="post"> <select name="name"> <option >--SELECT--</option> {% for job in all_pekerjaan%} <option value="{{job.id}}" {% if job.id == current_name %}selected="selected"{% endifequal %}> {{job.name}} </option> {% endfor %} </select> {% csrf_token %} <input type="submit" class="btn btn-success" value="submit" > </form> anyone know how to fix this issue? -
Django not displaying HTML template correctly
I am trying to load a test template using Django on Ubuntu. The template has loaded correctly in terms of errors. I downloaded a custom template from a website and I loaded up all of what it asked for: Jquery, Bootstrap and their own custom css also images and fonts. The site returns no errors in the console but it looks like this: When it supposed to look like this: The console returns no errors at all. The html files are practically the same except for the import statements for the files being replace with {% static 'css/mycssfiles.css' %} Any advice at all? -
How do you make a lowercase field in a django model?
With this method, I can make a field save as lowercase, but this does not change the field in the existing model (that is in memory). def get_prep_value(self, value): value = super(LowercaseField, self).get_prep_value(value) if value is not None: value = value.lower() return value I'm having a hard time figuring out how to force this field to lowercase without overriding save and doing the change there. But that splits the logic for this lowercase field. I'd like all of it in the field. What do I override so that setting this value forces lowercase in memory AND on in the DB? I don't want to change a form, I want all the lowercase logic contained inside the field class. -
show images uploaded by admin in html template
I am new to django and I saw solutions for my problem but none worked. I make admin upload images as you see in Item class in models.py : from django.db import models from django.contrib import admin class Customer (models.Model): username = models.CharField(max_length=500) email = models.CharField(max_length=1000 , unique=True) phone = models.IntegerField() address = models.CharField(max_length=3000) class Category(models.Model): category_title = models.CharField(max_length=100 , unique=True) def __str__(self): return self.category_title class Order (models.Model): time = models.DateTimeField(auto_now_add=True) total = models.IntegerField() created_by = models.ForeignKey(Customer, related_name='orders') class Item (models.Model): name = models.CharField(max_length=100 ,unique=True) details = models.CharField(max_length=1000) price = models.IntegerField() item_logo = models.ImageField(upload_to='res/static/res/images') category = models.ForeignKey(Category, related_name="items" ,on_delete= models.CASCADE) def __str__(self): return self.name class ItemInline(admin.TabularInline): model = Item class CategoryAdmin(admin.ModelAdmin): inlines = [ ItemInline, ] so how can I make those images appear in my HTML ( note: html code works fine but a small default image field appear instead of image ) : {% extends 'res/menu.html' %} {% block content %} <h1>hello</h1> <table class="table table-striped table-bordered" style="text-align: left ; border-color: black;" id="pizza_table"> <tbody> {% for item in items %} <td> {{ item.name }} <p>{{ item.details }}</p> </td> <td> <img src="{{item.item_logo}}"> </td> <td> </td> <td> <button type="button" class="btn btn-success" style="margin: 5px ;" onclick="additem('Seafood Pizza', 20 ) ;">Add</button> </td> {% … -
Django: Testing a CreateView that takes an argument from URL
I am using a CreateView with a custom form_valid function. On the test server, everything works fine. But as I started writing the unittests, the test for creating a model containing a foreign key is not passing. Any help or further questions would be greatly appreciated. I hope I formatted this to your guys' liking The classes are: class Parent(models.Model): name = models.CharField(max_length=10) class Child(models.Model): name = models.CharField(max_length=10) parent = models.ForeignKey(Father,on_delete=models.PROTECT) And in the urls.py we have the following URLs path('newparent/',views.AddNewParent.as_view(),name='new-parent'), path('parent/<int:parent_id>',views.ParentDetail.as_view(), name='parent-detail'), path('parent/<int:parent_id>/newchild',views.AddNewChild.as_view(), name='new-child') In views.py we have class AddNewParent(CreateView): model=Parent fields=['name'] class AddNewChild(CreateView): model=Child fields=['name'] def form_valid(self,form): form.instance.parent = Parent.objects.get(pk=self.kwargs['parent_id'] return super().form_valid(form) In tests.py, I have the following two tests class TestCreateViews(TestCase): def setUp(self): self.client = Client() def test_create_parent(self): createurl = reverse('new-parent') form_data = {'name':'John'} self.client.post(createurl,form_data) self.assertEqual(Parent.objects.last().name,'John') def test_create_child(self): p=Parent(name='John') p.save() createurl = reverse('new-child',args=[p.id]) form_data = {'name':'Dave'} self.client.post(createurl,form_data) self.assertEqual(Child.objects.last().parent_set.last().name,'John') The second test is failing to create a child instance in the database, and the HttpResponse that comes back is 200? This is a simplified case from a larger project I've been working on -
Annotate a queryset by a values queryset
I want to annotate a count of objects to a queryset, which I know how to do, but I want the objects counted to have their own filtering. This works well; first_model_qs = FirstModel.objects.filter(do a bunch of filtering) grouped_values_qs = first_model_qs.values('second_model').annotate(Count('pk')) So I now have a nice queryset with all the first_model counts grouped by second_model ids. Awesome. What I'ld like to do now is something like; secound_model_qs = SecondModel.objects.annotate(first_model_count = grouped_values_qs) And then be able to say secound_model_qs.first().first_model_count Is this possible? -
Django1.10: how to create 2 objects with foreign key relationship in one transaction
I have 2 models: class Vendor(models.Model): admin = models.ForeignKey(User) ... class User(models.Model): ... I want to create the user and vendor in one transaction: with transaction.atomic(): user = User(name="test") user.save() vendor = Vendor(admin=user) vendor.save() But I get error : ValueError: save() prohibited to prevent data loss due to unsaved related object 'admin'. How to fix this error? How to create these 2 objects in 1 transaction? -
efficient way to send a temporary message from admin to a specific user in django
i'm trying to send a temporary message/alert for a specific user on my app. I've managed to do it using this approach and i wanna know if there is an efficient/easier way to do it . models.py class Indar(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE , related_name='indars') content = models.CharField(max_length=120) start = models.DateField(auto_now=False, auto_now_add=False) end = models.DateField(auto_now=False, auto_now_add=False) views.py def home(request): qs = Indar.objects.filter(start__lte=timezone.now().date(),end__gte=timezone.now().date(),user=request.user) return render (request, 'home.html' , {'qs':qs}) home.html <div class="alert alert-warning" role="alert"> {% for obj in qs %} {{ obj.content }} {% endfor %} </div> -
Are ModelSerializers meant to be written on a per-view basis?
I am writing a Django app, which is huge and has a large number of API endpoints. This app uses DRF to serialize the information being sent to the frontend via JSON, and deserialize the information sent via JSON from the frontend. For ease of explaining my situation, let's consider a simplistic model. So let's say I have a model A. class A(models.Model): field1 = models.CharField(max_length=255) field2 = models.CharField(max_length=255) field3 = models.CharField(max_length=255) I have views for scenarios like these. create: User enters field1, based on which field2 and field3 will be populated and saved show: Only field2 will be shown on every model in the matching queryset show_full: Both field2 and field3 will be shown on every model in the matching queryset This brings me to my questions. Should I write one ModelSerializer each for all the views above? Or does DRF have some facility to specify model field names in the view itself? If serializers are meant to be written on a per-view basis, aren't serializers more tied to views than models? Thanks for helping me out. Neither the DRF documentation, nor any number of Google searches managed to solve my issue. -
Django Passing Multiple Views from Different Apps to the Same Template
I have a django shop application where all the Products are listed on one page via listview (no individual product pages). But my cart is rendered on a different app/template. When products are added to the cart they go to the other cart template. How can I combine the views into one? Thanks in advance. Carts App views.py from django.shortcuts import render, redirect from catalogue.models import Product from .models import Cart # Create your views here. def cart_home(request): cart_obj, new_obj = Cart.objects.new_or_get(request) return render(request, "carts/carts.html", {"cart": cart_obj}) def cart_update(request): product_id = request.POST.get('product_id') if product_id is not None: try: product_obj = Product.objects.get(id=product_id) except Product.DoesNotExist: print("Product is gone") return redirect("cart:home") cart_obj, new_obj = Cart.objects.new_or_get(request) if product_obj in cart_obj.products.all(): cart_obj.products.remove(product_obj) else: cart_obj.products.add(product_obj) return redirect("cart:home") This is views.py from Catalogue app from django.views.generic import ListView from django.shortcuts import render from . import models from .models import Product from carts.models import Cart class ProductListView(ListView): model = models.Product template_name = "catalogue/catalogue.html" def get_context_data(self, *args, **kwargs): context = super(ProductListView, self).get_context_data(*args, **kwargs) cart_obj, new_obj = Cart.objects.new_or_get(self.request) context['cart'] = cart_obj cat_appetizers = Product.objects.filter(category__name='Appetizers') cat_alltimefavourites = Product.objects.filter(category__name='All Time Favourites') cat_baltidishes = Product.objects.filter(category__name='Balti Dishes') cat_biryanidishes = Product.objects.filter(category__name='Biryani Dishes') cat_bread = Product.objects.filter(category__name='Bread') cat_drinks = Product.objects.filter(category__name='Drinks') cat_grillroastdishes = Product.objects.filter(category__name='Grill & Roast Dishes') cat_housespecials … -
Inline Disabling
I am disabling a button inline using Django conditions <button {% if order.return_available == True %} disabled="disabled" {% endif%} class="class1 class2 {% if order.return_available == True %} disabled {% endif %}"> Problem is that when I play around with the Chrome Dev Tools and manually remove those inline disables, it removes the disable formatting and I am able to once again trigger the POST for the form and furthermore it actually updates the database and performs the action of the button. Will this be the same for when deployed and for the end user? Do I need to change this or will the disable be a hard feature once deployed?