Posts

Showing posts from January, 2021

Important Django Query Demos

#***(1)Returns all customers from customer table customers = Customer.objects.all() #(2)Returns first customer in table firstCustomer = Customer.objects.first() #(3)Returns last customer in table lastCustomer = Customer.objects.last() #(4)Returns single customer by name customerByName = Customer.objects.get( name = 'Peter Piper' ) #***(5)Returns single customer by name customerById = Customer.objects.get( id = 4 ) #***(6)Returns all orders related to customer (firstCustomer variable set above) firstCustomer.order_set.all() #(7)***Returns orders customer name: (Query parent model values) order = Order.objects.first()  parentName = order.customer.name #(8)***Returns products from products table with...

The Dashboard Accounts Django Source

VIEWS from  django.shortcuts  import  render, redirect  from  django.http  import  HttpResponse from  django.forms  import  inlineformset_factory from  django.contrib.auth.forms  import  UserCreationForm from  django.contrib.auth  import  authenticate, login, logout from  django.contrib  import  messages from  django.contrib.auth.decorators  import  login_required # Create your views here. from  .models  import  * from  .forms  import  OrderForm, CreateUserForm from  .filters  import  OrderFilter def   registerPage ( request ):      if  request.user.is_authenticated:          return  redirect( 'home' )      else :         form = CreateUserForm() ...