-coding utf8- from django contrib auth models import User from django

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#-*-coding:utf8-*-
from django.contrib.auth.models import User
from django.db import models
from django.utils.translation import ugettext_lazy as _
from goods.models import Good
from accounts.models import ClientProfile
from django.contrib import admin
import datetime as dt
class Order(models.Model):
user = models.ForeignKey(User)
opened = models.BooleanField(default=True, verbose_name=u"Открыт")
date_create = models.DateTimeField(auto_now_add=True, verbose_name=u"Дата создания")
all_price = models.FloatField(default=0, verbose_name=u"Общая стоимость", max_length=8)
def closed(self):
self.opened = False
self.date_create = dt.datetime.now()
self.all_price = self.get_all_price()
self.save()
def get_all_price(self):
goods = self.goodtobuy_set.all()
all_price = 0
for good in goods:
all_price += good.good_to.price * good.count
return all_price
def __unicode__(self):
return "%i - %s" % (self.id, self.user.username)
class Meta:
ordering = ['-date_create']
verbose_name = u"Заказ"
verbose_name_plural = u"Заказы"
class GoodToBuy(models.Model):
good_to = models.ForeignKey(Good)
order = models.ForeignKey(Order)
count = models.IntegerField(default=0, max_length=3, verbose_name=u"Количество")
def __unicode__(self):
return self.good_to.title
#-*-coding:utf8-*-
from django.db import models
from django.contrib import admin
import datetime as dt
class GoodBrand(models.Model):
name = models.CharField(max_length=64, verbose_name=u"Название")
description = models.TextField(verbose_name=u"Описание", blank=True)
city = models.CharField(max_length=64, verbose_name=u"Город", blank=True)
def __unicode__(self):
return "%s - %s" % (self.name, self.city)
class Meta:
verbose_name = u"Компания"
verbose_name_plural = u"Компании"
class GoodSeries(models.Model):
brand = models.ForeignKey(GoodBrand)
series_name = models.CharField(max_length=250, verbose_name=u"Название")
description = models.TextField(verbose_name=u"Описание", blank=True)
def __unicode__(self):
return "%s - %s" % (self.brand.name, self.series_name)
class Meta:
verbose_name = u"Серия товаров"
verbose_name_plural = u"Серии товаров"
class Good(models.Model):
group_good = models.ForeignKey(GoodSeries, verbose_name=u"Группа")
title = models.CharField(max_length=250, verbose_name=u"Название")
barcode = models.CharField(max_length=24, verbose_name=u"Штрих код")
count = models.IntegerField(max_length=4, verbose_name=u"Остаток")
image = models.ImageField(upload_to='goods/', verbose_name=u"Фотография",
blank=True, default="goods/default.png")
big_image = models.ImageField(upload_to='goods/big/', verbose_name=u"Большая фотография",
blank=True, default="goods/big/default.png")
description = models.TextField(verbose_name=u"Описание", blank=True)
price = models.FloatField(verbose_name=u"Цена", max_length=6)
volume = models.CharField(max_length=32, verbose_name=u"Объем")
def __unicode__(self):
return "%s %s" % (self.barcode, self.title)
class Meta:
ordering = ['barcode']
verbose_name = u"Товар"
verbose_name_plural = u"Товары"