Skip to content

Commit

Permalink
Merge pull request #19 from jamedadi/feature_address_mohammad
Browse files Browse the repository at this point in the history
merge Feature address mohammad
  • Loading branch information
MrMohammadY authored Aug 31, 2021
2 parents 1dd3224 + cc998e7 commit 2dab97d
Show file tree
Hide file tree
Showing 20 changed files with 540 additions and 20 deletions.
13 changes: 10 additions & 3 deletions address/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.contrib import admin
from .models import State, City, Area, Address
from .models import State, City, Area, ServiceAddress, CustomerAddress


@admin.register(State)
Expand All @@ -22,8 +22,15 @@ class AreaAdmin(admin.ModelAdmin):
search_fields = ('name',)


@admin.register(Address)
class AddressAdmin(admin.ModelAdmin):
@admin.register(ServiceAddress)
class ServiceAddressAdmin(admin.ModelAdmin):
list_display = ('state', 'city', 'area', 'floor', 'plaque')
list_filter = ('state', 'city')
search_fields = ('area', 'floor', 'plaque')


@admin.register(CustomerAddress)
class CustomerAddressAdmin(admin.ModelAdmin):
list_display = ('customer_user', 'state', 'city', 'area', 'floor', 'plaque')
list_filter = ('state', 'city')
search_fields = ('area', 'floor', 'plaque')
28 changes: 28 additions & 0 deletions address/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from django import forms

from address.models import CustomerAddress, ServiceAddress

base_fields = ('state', 'city', 'area', 'street', 'alley', 'floor', 'plaque')
base_widgets = {
'state': forms.Select(attrs={'class': 'form-control'}),
'city': forms.Select(attrs={'class': 'form-control'}),
'area': forms.Select(attrs={'class': 'form-control'}),
'street': forms.TextInput(attrs={'class': 'form-control'}),
'alley': forms.TextInput(attrs={'class': 'form-control'}),
'floor': forms.NumberInput(attrs={'class': 'form-control'}),
'plaque': forms.NumberInput(attrs={'class': 'form-control'}),
}


class CustomerAddressCreateUpdateForm(forms.ModelForm):
class Meta:
model = CustomerAddress
fields = base_fields
widgets = base_widgets


class ServiceAddressCreateUpdateForm(forms.ModelForm):
class Meta:
model = ServiceAddress
fields = base_fields
widgets = base_widgets
55 changes: 55 additions & 0 deletions address/migrations/0002_auto_20210830_1305.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Generated by Django 3.2 on 2021-08-30 08:35

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('address', '0001_initial'),
]

operations = [
migrations.CreateModel(
name='CustomerAddress',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_time', models.DateTimeField(auto_now_add=True, verbose_name='created time')),
('modified_time', models.DateTimeField(auto_now=True, verbose_name='modified time')),
('floor', models.SmallIntegerField(verbose_name='floor')),
('plaque', models.SmallIntegerField(verbose_name='plaque')),
],
options={
'verbose_name': 'CustomerAddress',
'verbose_name_plural': 'CustomerAddresses',
'db_table': 'customer_address',
},
),
migrations.CreateModel(
name='ServiceAddress',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_time', models.DateTimeField(auto_now_add=True, verbose_name='created time')),
('modified_time', models.DateTimeField(auto_now=True, verbose_name='modified time')),
('floor', models.SmallIntegerField(verbose_name='floor')),
('plaque', models.SmallIntegerField(verbose_name='plaque')),
],
options={
'verbose_name': 'ServiceAddress',
'verbose_name_plural': 'ServiceAddresses',
'db_table': 'service_address',
},
),
migrations.RemoveField(
model_name='address',
name='area',
),
migrations.RemoveField(
model_name='address',
name='city',
),
migrations.RemoveField(
model_name='address',
name='state',
),
]
55 changes: 55 additions & 0 deletions address/migrations/0003_auto_20210830_1305.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Generated by Django 3.2 on 2021-08-30 08:35

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('service', '0002_alter_service_address'),
('address', '0002_auto_20210830_1305'),
('accounts', '0001_initial'),
('payment', '0002_alter_invoice_address'),
]

operations = [
migrations.DeleteModel(
name='Address',
),
migrations.AddField(
model_name='serviceaddress',
name='area',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='s_addresses', to='address.area', verbose_name='area'),
),
migrations.AddField(
model_name='serviceaddress',
name='city',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='s_addresses', to='address.city', verbose_name='city'),
),
migrations.AddField(
model_name='serviceaddress',
name='state',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='s_addresses', to='address.state', verbose_name='state'),
),
migrations.AddField(
model_name='customeraddress',
name='area',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='c_addresses', to='address.area', verbose_name='area'),
),
migrations.AddField(
model_name='customeraddress',
name='city',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='c_addresses', to='address.city', verbose_name='city'),
),
migrations.AddField(
model_name='customeraddress',
name='state',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='c_addresses', to='address.state', verbose_name='state'),
),
migrations.AddField(
model_name='customeraddress',
name='user',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='c_addresses', to='accounts.customer', verbose_name='customer'),
),
]
33 changes: 33 additions & 0 deletions address/migrations/0004_auto_20210830_1327.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 3.2 on 2021-08-30 08:57

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('address', '0003_auto_20210830_1305'),
]

operations = [
migrations.AddField(
model_name='customeraddress',
name='alley',
field=models.TextField(blank=True),
),
migrations.AddField(
model_name='customeraddress',
name='street',
field=models.TextField(blank=True),
),
migrations.AddField(
model_name='serviceaddress',
name='alley',
field=models.TextField(blank=True),
),
migrations.AddField(
model_name='serviceaddress',
name='street',
field=models.TextField(blank=True),
),
]
33 changes: 33 additions & 0 deletions address/migrations/0005_auto_20210830_1329.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 3.2 on 2021-08-30 08:59

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('address', '0004_auto_20210830_1327'),
]

operations = [
migrations.AlterField(
model_name='customeraddress',
name='alley',
field=models.CharField(max_length=30),
),
migrations.AlterField(
model_name='customeraddress',
name='street',
field=models.CharField(max_length=50),
),
migrations.AlterField(
model_name='serviceaddress',
name='alley',
field=models.CharField(max_length=30),
),
migrations.AlterField(
model_name='serviceaddress',
name='street',
field=models.CharField(max_length=50),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2 on 2021-08-31 10:06

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('address', '0005_auto_20210830_1329'),
]

operations = [
migrations.RenameField(
model_name='customeraddress',
old_name='user',
new_name='customer_user',
),
]
48 changes: 39 additions & 9 deletions address/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from django.db import models

from accounts.models import Customer
from library.models import BaseModel
from django.utils.translation import ugettext_lazy as _

Expand Down Expand Up @@ -36,25 +38,53 @@ class Area(BaseModel):
city = models.ForeignKey(City, verbose_name=_('city'), related_name='areas', on_delete=models.CASCADE)

def __str__(self):
return f'{self.city.name} - {self.name})'
return f'{self.city.name} - {self.name}'

class Meta:
verbose_name = _('Area')
verbose_name_plural = _('Areas')
db_table = 'area'


class Address(BaseModel):
state = models.ForeignKey(State, verbose_name=_('state'), related_name='addresses', on_delete=models.CASCADE)
city = models.ForeignKey(City, verbose_name=_('city'), related_name='addresses', on_delete=models.CASCADE)
area = models.ForeignKey(Area, verbose_name=_('area'), related_name='addresses', on_delete=models.CASCADE)
class BaseAddress(BaseModel):
street = models.CharField(max_length=50)
alley = models.CharField(max_length=30)
floor = models.SmallIntegerField(verbose_name=_('floor'))
plaque = models.SmallIntegerField(verbose_name=_('plaque'))

class Meta:
abstract = True


class CustomerAddress(BaseAddress):
customer_user = models.ForeignKey(
Customer,
verbose_name=_('customer'),
related_name='c_addresses',
on_delete=models.CASCADE
)
state = models.ForeignKey(State, verbose_name=_('state'), related_name='c_addresses', on_delete=models.CASCADE)
city = models.ForeignKey(City, verbose_name=_('city'), related_name='c_addresses', on_delete=models.CASCADE)
area = models.ForeignKey(Area, verbose_name=_('area'), related_name='c_addresses', on_delete=models.CASCADE)

def __str__(self):
return f'{self.customer_user} - {self.city} - {self.area}'

class Meta:
verbose_name = _('CustomerAddress')
verbose_name_plural = _('CustomerAddresses')
db_table = 'customer_address'


class ServiceAddress(BaseAddress):
state = models.ForeignKey(State, verbose_name=_('state'), related_name='s_addresses', on_delete=models.CASCADE)
city = models.ForeignKey(City, verbose_name=_('city'), related_name='s_addresses', on_delete=models.CASCADE)
area = models.ForeignKey(Area, verbose_name=_('area'), related_name='s_addresses', on_delete=models.CASCADE)

def __str__(self):
return f'{self.area} - {self.floor} - {self.plaque}'
return f'{self.city} - {self.area}'

class Meta:
verbose_name = _('Address')
verbose_name_plural = _('Addresses')
db_table = 'address'
verbose_name = _('ServiceAddress')
verbose_name_plural = _('ServiceAddresses')
db_table = 'service_address'
22 changes: 22 additions & 0 deletions address/templates/address/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<!-- Bootstrap -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-KyZXEAg3QhqLMpG8r+8fhAXLRk2vvoC2f3B09zVXn8CA5QIVfZOJ3BCsw2P0p/We" crossorigin="anonymous">

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/js/bootstrap.bundle.min.js"
integrity="sha384-U1DAWAznBHeqEIlVSCgzq+c9gqGAJn5c/t99JyeKa9xxaYpSvHU5awsuZVVFIhvj"
crossorigin="anonymous"></script>

<title>{% block title %} {% endblock %}</title>
</head>
<body>
<div class="container pt-3">
{% block content %}
{% endblock %}
</div>

</body>
</html>
8 changes: 8 additions & 0 deletions address/templates/address/create_update_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% extends 'address/base.html' %}
{% block content %}
<form method="POST">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="submit" class="btn btn-warning">
</form>
{% endblock %}
11 changes: 11 additions & 0 deletions address/templates/address/delete_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends 'address/base.html' %}
{% block content %}
<div>
<form method="POST">
{% csrf_token %}
<p>Are you sure to delete address ({{ object.state }} | {{ object.area }})?</p>
<input type="submit" value="delete" class="btn btn-danger">
</form>
<a href="{% url 'address:customer-address-update' object.id %}" class="btn btn-warning" style="margin-top: 20px">cancel</a>
</div>
{% endblock %}
16 changes: 16 additions & 0 deletions address/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from django.urls import path

from .views import CustomerAddressCreateView, CustomerAddressUpdateView, CustomerAddressDeleteView, \
ServiceAddressCreateView, ServiceAddressUpdateView

app_name = 'address'

urlpatterns = [
path('customer/create/', CustomerAddressCreateView.as_view(), name='customer-address-create'),
path('service/create/<int:service_pk>/', ServiceAddressCreateView.as_view(), name='service-address-create'),

path('customer/update/<int:pk>/', CustomerAddressUpdateView.as_view(), name='customer-address-update'),
path('service/update/<int:pk>/', ServiceAddressUpdateView.as_view(), name='service-address-update'),

path('customer/delete/<int:pk>/', CustomerAddressDeleteView.as_view(), name='customer-address-delete'),
]
Loading

0 comments on commit 2dab97d

Please sign in to comment.