def product_edit_view(request, id):
product = Product.objects.get(id=id)
form = ProductForm(request.POST or None, request.FILES or None, instance=product)
if form.is_valid():
if product.price != form.cleaned_data['price']:
log = Log()
log.product = product
log.event = 'changed_price'
log.description = 'old: ' + str(product.price) + ' , new: ' + str(form.cleaned_data['price'])
log.qty = product.qty
log.staff = request.user
log.save()
form.save()
form_valid
добавить логику для создания профиля. Посмотрите в доках что делает этот метод(он только создает Юзера + возвращает респонс)def create_profile(sender, instance, created, **kwargs):
""" Creates profile for user """
CustomerProfile.objects.get_or_create(user=instance)
post_save.connect(create_profile, sender=USER_MODEL)
Django Oscar
(https://github.com/django-oscar/django-oscar) сделана полностью своя админка. Все действия только в ней. Можно посмотреть как там реализовано. if profile_form.is_valid():
customer_profile = profile_form.save(commit=False)
customer_profile.user = self.object
customer_profile.save()
post_data = self.profile_form_valid(request)
{% thumbnail image.original "440x400" upscale=False as thumb %}
format
в thumbnail
по умолчанию 'JPEG', а .JPEG не поддерживает прозрачность, поэтому и были такие проблемы. Все решилось очень просто:{% thumbnail image.original "440x400" upscale=False format="PNG" as thumb %}
$('#id_child_id').bind('change', function () {
var url = $(this).val();
if (url != '') {
window.location = url;
}
return false;
});
$(document).ready(function () {
var product = window.location.pathname
$('#id_child_id').val(product);
});
class Product(AbstractProduct):
...
num_in_stock_product = models.PositiveIntegerField(
_("Number in stock(product)"), blank=True, null=True)
stock_update = models.IntegerField(
_("Stock update"), blank=True, null=True)
def save(self, *args, **kwargs):
if self.stock_update:
if not self.num_in_stock_product:
self.num_in_stock_product = 0
self.num_in_stock_product += self.stock_update
self.stock_update = None
super(AbstractProduct, self).save(*args, **kwargs)
self.attr.save()
class StockRecord(AbstractStockRecord):
...
@property
def num_in_stock_stockrecord(self):
return self.product.num_in_stock_product
@property
def net_stock_level(self):
"""
The effective number in stock (eg available to buy).
This is correct property to show the customer, not the num_in_stock
field as that doesn't account for allocations. This can be negative in
some unusual circumstances
"""
all_allocations = 0
for stockrecord in self.product.stockrecords.all():
if stockrecord.num_allocated is not None:
all_allocations += stockrecord.num_allocated
if self.num_in_stock_stockrecord is None:
return 0
return self.num_in_stock_stockrecord - all_allocations
$ pip freeze > requirements.txt