python - Implementing product upload dynamically using Django 1.6 -


so using admin interface add product information different items on site. looking add product information models template view, every time add new product using admin interface, template generate new li tag current product information , picture used of entered data within admin interface.

i have not yet implemented template logic in views.py yet stumped on how wrap head around making whole process happen. can guide me on how implement solution?

thank you!

here code below:

models.py

from __future__ import unicode_literals  django.db import models django.utils.translation import ugettext_lazy _  import datetime  class designer(models.model):     name = models.charfield(max_length=254, blank=true, null=true)     label_name = models.charfield(max_length=254, blank=true, null=true)     description = models.textfield(null=true, blank=true)     specialites = models.charfield(max_length=254,  null=true, blank=true)     image = models.imagefield(upload_to='images/designers/main',max_length=100, null=true) #for argument upload_to, add static folder , generated image stored in suing path specified      #for admin purposes, track , see if still active administrative users     is_active = models.booleanfield(default=true)       #metadata     class meta:        verbose_name = _("designer information")        verbose_name_plural = _("designers")      #helps return meaningful, show within admin interface easy interaction     def __unicode__(self):         return "{0} {1}".format(self.name, self.label_name)  class boutique(models.model):     name = models.charfield(max_length=254, blank=true, null=true)     address = models.charfield(max_length=255, blank=true, null=true)         city = models.charfield(max_length=50, null=true, blank=true)     state = models.charfield(max_length=2, null=true, blank=true)     zipcode = models.integerfield(max_length=5, null=true, blank=true)     boutique_website = models.urlfield(max_length=200,  null=true, blank=true)      #for admin purposes, track product see active administrative users     is_active = models.booleanfield(default=true)      #foreign keys & other relationships     designer = models.foreignkey(designer)      #metadata     class meta:       verbose_name = _("boutique information")       verbose_name_plural = _("boutiques")      #helps return meaningful, show within admin interface easy interaction     def __unicode__(self):         return "{0}, {1}, {2}".format(self.name, self.city, self.state)  class productcategory(models.model):     name = models.charfield(max_length=255l, blank=true, null=true)     slug = models.slugfield(max_length=50, unique=true, help_text='unique value product page url, created name.')      #for admin purposes, track , see if still active administrative users     is_active = models.booleanfield(default=true)      #for admin purposes, track when add each product , each product updated administrative users     created_at = models.datetimefield(auto_now_add=true)     updated_at = models.datetimefield(auto_now=true)      #metadata     class meta:         verbose_name = _("product category")         verbose_name_plural = _("product categories")      #helps return meaningful, show within admin interface easy interaction     def __unicode__(self):         return "{0}".format(self.name)  class product(models.model):     name = models.charfield(max_length=254, blank=true, null=true)     description = models.textfield(blank=true, null=true)         color_name = models.charfield(max_length=254, null=true, blank=true)     size_types = models.charfield(max_length=7, null=true, blank=true)     product_price = models.decimalfield(max_digits=9,decimal_places=2)     old_price = models.decimalfield(max_digits=9,decimal_places=2, blank=true,default=0.00) #to show original price if, new price has been added     product_tags = models.charfield(max_length=254, null=true, blank=true, help_text='comma-delimited set of seo keywords product tag area')     novelty = models.charfield(max_length=254, null=true, blank=true)     product_website = models.urlfield(max_length=200,  null=true, blank=true) #to show other sites users, can purchase particular product     image = models.imagefield(upload_to='images/products/main',max_length=100, null=true) #for argument upload_to, add static folder , generated image stored in suing path specified     slug = models.slugfield(max_length=255, unique=true, help_text='unique value product page url, created name.')    #this shows when each item uploaded & who, user      uploaded_by = models.charfield(max_length=254, blank=true, null=true)     uploaded_at = models.datetimefield(auto_now=true)    #for admin purposes, track , see if still active administrative users     is_active = models.booleanfield(default=true)      #foreign keys & other relationships     designer = models.foreignkey(designer)     boutique = models.foreignkey(boutique)     category = models.foreignkey(productcategory)      #metadata     class meta:         verbose_name = _("product")         verbose_name_plural = _("products")      #helps return meaningful, show within admin interface easy interaction     def __unicode__(self):         return "{0}".format(self.name) 

admin.py

from __future__ import unicode_literals  django.contrib import admin products.models import designer, product, productcategory, boutique   class designeradmin(admin.modeladmin):      list_display = ["name", "label_name", "description", "specialites", "image", "is_active"]     search_fields = ["name", "label_name"]     list_per_page = 50  class productadmin(admin.modeladmin):      list_display = ["name", "description", "color_name", "size_types", "product_price", "old_price", "product_tags", "novelty","product_website", "image", "slug", "uploaded_by", "uploaded_at", "is_active"]     search_fields = ["name", "product_price"]     list_per_page = 25  class productcategoryadmin(admin.modeladmin):       list_display = ["name", "slug", "is_active", "created_at", "updated_at"]     search_fields = ["name"]     list_per_page = 25  class boutiqueadmin(admin.modeladmin):      list_display = ["name", "address", "city", "state", "zipcode", "boutique_website", "is_active"]     search_fields = ["name"]     list_per_page = 10   #register models below admin.site.register(boutique, boutiqueadmin) admin.site.register(designer, designeradmin) admin.site.register(product, productadmin) admin.site.register(productcategory, productcategoryadmin) 

forms.py

from __future__ import unicode_literals  django import forms  django.forms import extras, modelform  products.models import designer, product, productcategory, boutique  class designerform(modelform):     class meta:         model = designer  class productform(modelform):     class meta:         model = product  class boutiqueform(modelform):     class meta:         model = boutique  class productcategoryform(modelform):     class meta:         model = productcategory 

views.py

from __future__ import unicode_literals  django.http import http404, httpresponseforbidden django.shortcuts import redirect, get_object_or_404 django.utils.http import base36_to_int, int_to_base36 django.core.urlresolvers import reverse django.utils.translation import ugettext_lazy _ django.views.generic.base import templateresponsemixin, view django.views.generic.edit import formview  django.contrib import auth, messages django.contrib.sites.models import get_current_site django.shortcuts import render  products.forms import productform, productcategoryform products.forms import boutiqueform products.forms import designerform  products.models import boutique, product, productcategory, designer    class productview(formview):      template_name = "product_detail/product.html"     form_class = productform     template_var={}       def __init__(self, *arg):         super(productview, self).__init__()         self.arg = arg    class productcategoryview(formview):      form_class = productcategoryform     template_var={}       def __init__(self, *arg):         super(productcategory, self).__init__()         self.arg = arg 

the easiest way simple listview django's generic class-based views.

first, string views.py:

from django.views.generic import listview  class productlistview(listview):      model = product     template_name = 'product/list_view.html' # edit whatever template is. 

remember edit urls.py:

from .views import productlistview  urlpatterns = patterns('',     ...     url(r'^product/$', productlistview.as_view(), name='list'), # edit url path , name desired     ... ) 

then, make template:

<div class="jumbotron">     <ul>     {% product in products %}         <li>{{ product.name }}: {{ product.description }} <img src="{{ product.image.url }}" >     {% endfor %}     </ul> </div> 

this basic template you'll want customize. each product in database, display name, description, , image. can customize fields desire.

other potential issues:

1) sure provide correct path template in listview.

2) set media_url , other media settings allow product image display.

3) @ other customization options in listview (see documentation here.)


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -