from django.urls import path

from django.contrib.auth import views as auth_views

from . import views

urlpatterns = [
path('register/', views.registerPage, name="register"),
path('login/', views.loginPage, name="login"),
path('logout/', views.logoutUser, name="logout"),

path('', views.home, name="home"),
path('user/', views.userPage, name="user-page")…
from django.db.models.signals import post_save
from django.contrib.auth.models import User
from django.contrib.auth.models import Group


from .models import Customer

def customer_profile(sender, instance, created, **kwargs):
if created:
group = Group.objects.get(name='customer')
instance.groups.add(group)
Customer.objects.create(
user=instance,
name=instance.username,
)
print('Profile created!')

post_save.connect(customer_profile, sender=User)
Customer.objects.create(
user=instance,
name=instance.username,
)
from django.apps import AppConfig

class AccountsConfig(AppConfig):
name = 'accounts'

def ready(self):
import accounts.signals
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'accounts.apps.AccountsConfig',
'django_filters',
]
class Customer(models.Model):
user = models.OneToOneField(User, null=True, on_delete=models.CASCADE)
name = models.CharField(max_length=200, null=True)
phone = models.CharField(max_length=200, null=True)
email = models.CharField(max_length=200, null=True)
date_created = models.DateTimeField(auto_now_add=True, null=True)

def __str__(self):
return self.name
{%  extends 'accounts/main.html' %}
{% block content %}
{% include 'accounts/status.html' %}

<h3>User Profile</h3>

{% endblock content %}
def userPage(request):
context = {}
return render(request, 'accounts/user.html', context)
path('user/', views.userPage, name="user-page"),
from django.http import HttpResponse
from django.shortcuts…
path('register/', views.registerPage, name="register"),
path('login/', views.loginPage, name="login"),
path('logout/', views.logoutUser, name="logout"),
from django.forms import ModelForm
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User
from django import forms



from .models …
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'accounts',
'django_filters',
]
import django_filters
from django_filters import DateFilter, CharFilter

from .models import *

class OrderFilter(django_filters.FilterSet): …
<a class="btn btn-outline-info  btn-sm btn-block" href="{% url 'create_order' customer.id %}">Place Order</a>
path('create_order/<str:pk>/', views.createOrder, name='create_order'),
def createOrder(request, pk):
OrderFormSet = inlineformset_factory(Customer, Order, fields=('product', 'status'), extra=10)
customer = Customer.objects.get(id=pk)
formset = OrderFormSet(queryset=Order.objects.none(), instance=customer)

if request.method == 'POST':
# print('Printing POST:', request.POST)
formset = OrderFormSet(request.POST, instance=customer)
if formset.is_valid():
formset.save()
return redirect('/')

context = {'form': formset}
return render(request, 'accounts/order_form.html', context)
{% extends 'accounts/main.html' %}
{% load static %}
{% block content %}
<div class="row">
<div class="col-md-6">
<div class="card card-body">
<form action="" method="POST">
{% csrf_token %}
{{ form.management_form }}
{% for field in form %}
{{field}}
<hr>
{% endfor %}
<input type="submit" name="Submit">
</form>
</div>
</div>
</div>

{% endblock %}
{% extends 'accounts/main.html' %}
{% load static %}
{% block content %}
<div class="row">
<div class="col-md-6">
<div class="card card-body">
<form action="" method="POST">
{% csrf_token %}
{{form}}
<input type="submit" name="Submit">
</form>
</div>
</div>
</div>

{% endblock %}
from django.forms import ModelForm
from .models import Order

class OrderForm(ModelForm)…
......
path('customer/<str:pk_test>/', views.customer),
......
def customer(request, pk_test):
customer = Customer.objects.get(id = pk_test)
orders = customer.order_set.all()
order_count = orders.count()

context = {'customer': customer, 'orders': orders, 'order_count': order_count}
return render(request, 'accounts/customer.html', context)
{%  extends 'accounts/main.html' %}

{%…

syawal 2016

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store