📅  最后修改于: 2023-12-03 14:40:46.831000             🧑  作者: Mango
Django 是一个高级 Python Web 框架,专注于简洁、快速开发和可扩展的 Web 应用程序。餐厅管理系统是其中一个基于 Django 框架开发的实例应用。这个系统可以帮助餐厅管理店面,点餐,下单等各项业务,提高工作效率。
店面管理:可以添加店面信息,例如地址、电话、开门时间、停车位等。
菜单管理:管理员可以添加、编辑、删除菜单,包括价格、品名、食材、口味等参数。用户可以查看菜单,点餐、加菜、删除等。
订单管理:管理员可以查看系统中所有的订单,掌握营业额度、菜品销售情况。用户可以查看自己的订单、付款、取消订单、评价等。
职员管理:管理员通过添加员工信息,分配角色、设置权限等,实现对职员的管理。
# models.py
class Store(models.Model):
name = models.CharField(max_length=50, unique=True)
address = models.CharField(max_length=100)
phone_number = models.CharField(max_length=20)
opening_time = models.TimeField()
closing_time = models.TimeField()
parking = models.BooleanField(default=False)
# views.py
def store_detail(request, store_id):
store = get_object_or_404(Store, pk=store_id)
return render(request, 'store_detail.html', {'store': store})
# models.py
class MenuItem(models.Model):
name = models.CharField(max_length=50, unique=True)
price = models.DecimalField(max_digits=6, decimal_places=2)
ingredients = models.CharField(max_length=200)
taste = models.CharField(max_length=20)
is_available = models.BooleanField(default=True)
picture = models.ImageField(upload_to='menu_pictures', blank=True, null=True)
category = models.ForeignKey(Category, on_delete=models.SET_NULL, null=True)
class Category(models.Model):
name = models.CharField(max_length=50, unique=True)
# views.py
def menu_list(request):
categories = Category.objects.all()
items = MenuItem.objects.filter(is_available=True)
return render(request, 'menu_list.html', {'categories': categories, 'items': items})
# models.py
class Order(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
store = models.ForeignKey(Store, on_delete=models.CASCADE)
items = models.ManyToManyField(MenuItem, through='ItemOrder')
status = models.CharField(max_length=50, choices=STATUS_CHOICES, default='pending')
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
payment_method = models.CharField(max_length=50, choices=PAYMENT_METHOD_CHOICES, default='cash')
total_price = models.DecimalField(max_digits=6, decimal_places=2)
class ItemOrder(models.Model):
item = models.ForeignKey(MenuItem, on_delete=models.CASCADE)
order = models.ForeignKey(Order, on_delete=models.CASCADE)
quantity = models.IntegerField(default=1)
# views.py
@login_required
def create_order(request, store_id):
store = get_object_or_404(Store, pk=store_id)
if request.method == 'POST':
form = OrderForm(request.POST)
if form.is_valid():
items = request.POST.getlist('items[]')
quantities = request.POST.getlist('quantities[]')
order = form.save(commit=False)
order.user = request.user
order.store = store
order.total_price = calculate_price(items, quantities)
order.save()
for i, item_id in enumerate(items):
ItemOrder.objects.create(item_id=item_id, order=order, quantity=quantities[i])
return redirect('order_detail', order_id=order.pk)
else:
form = OrderForm()
categories = Category.objects.all()
items = MenuItem.objects.filter(is_available=True)
context = {'store': store, 'form': form, 'categories': categories, 'items': items}
return render(request, 'create_order.html', context)
# models.py
class Staff(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
store = models.ForeignKey(Store, on_delete=models.CASCADE)
role = models.CharField(max_length=50, choices=ROLE_CHOICES, default='waiter')
ROLE_CHOICES = [
('waiter', '服务员'),
('chef', '厨师'),
('manager', '经理'),
]
# views.py
@login_required
def staff_list(request):
if request.user.is_manager:
staff_list = Staff.objects.filter(store=request.user.store)
context = {'staff_list': staff_list}
return render(request, 'staff_list.html', context)
else:
raise PermissionDenied
以上是针对餐厅管理系统的 Django 应用程序开发实例介绍。该应用程序可以通过 Django 框架的快速开发功能,快速部署上线,为餐厅的点餐、下单、管理等提供便捷。期望这份介绍,对大家有所帮助。