I'm also a beginner in python/django/mezzanine world, but here's what I
did, in a kind of a similar scenario.
I'm using cartridge <http://cartridge.jupo.org/index.html> and my products
are from different vendors, therefore I injected a custom
field<http://mezzanine.jupo.org/docs/model-customization.html#field-injection>in
cartridge's Product class. Added in settings.py:
EXTRA_MODEL_FIELDS = (
> (
> # Dotted path to field.
> "cartridge.shop.models.Product.clp_shop_vendor",
> # Dotted path to field class.
> "django.db.models.ForeignKey",
> # Positional args for field class.
> ("CLPShopVendor",),
> # Keyword args for field class.
> {
> "verbose_name": _("Vendor"),
> "related_name": "products",
> "default": None,
> "blank": True,
> "null": True,
> },
> ),
> # and other ...
> )
Then in my custom app `clp_shop`, I added vendor model called
`CLPShopVendor`, note app_label = "shop", this is to make sure this model
is used inside cartridge's shop app.
class CLPShopVendor(Displayable, Ownable, RichText, AdminThumbMixin):
> location = models.CharField(max_length=60, blank=True)
> @models.permalink
> def get_absolute_url(self):
> return "clp_vendor", (), {"slug": self.slug}
> class Meta:
> app_label = "shop"
> verbose_name = _("Shop Vendor")
> verbose_name_plural = _("Shop Vendors")
> ordering = ['title']
I registered it to be available in admin UI. and also ensured admin
`product` has it's new foreign vendor field. Relevant part of my
clp_shop.admin:
product_fieldsets = deepcopy(ProductAdmin.fieldsets)
> product_fieldsets[0][1]["fields"].insert(-1, "clp_shop_vendor")
> class CLPProductAdmin(ProductAdmin):
> fieldsets = product_fieldsets
> class CLPShopVendorAdmin(admin.ModelAdmin):
> pass
> admin.site.unregister(Product)
> admin.site.register(Product, CLPProductAdmin)
> admin.site.register(CLPShopVendor, CLPShopVendorAdmin)
,note unregister/register Product with the the new `fieldsets`.
Next I needed a vendor "page", which is not a mezzanine page, as Eduardo
mentioned this vendor "page" qualifies as "Non-page Content".
So I created my clp_shop.views.clp_vendor, added an entry for it in
clp_shop.url.py (which is of course included in the project's url.py)
def clp_vendor(request, slug):
> """
> Display vendor's page showing all products from this vendor.
> """
> conf.settings.use_editable()
> if request.is_ajax():
> template = "shop/ajax_load_products.html"
> else:
> template = "shop/clp_vendor.html"
> vendor = get_object_or_404(CLPShopVendor.objects, slug=slug)
> products = vendor.products.published(for_user=request.user)
> sort_options = [(slugify(option[0]), option[1])
> for option in conf.settings.SHOP_PRODUCT_SORT_OPTIONS]
> sort_by = request.GET.get("sort", sort_options[0][1])
> products = paginate(products.order_by(sort_by),
> request.GET.get("page", 1),
> conf.settings.SHOP_PER_PAGE_CATEGORY,
> conf.settings.MAX_PAGING_LINKS)
> products.sort_by = sort_by
> context = {
> "vendor": vendor,
> "products": products,
> }
> return render(request, template, context)
NOTE 1: My template is dynamically adjusted based on request type. AJAX
requests for loading more products uses different template.
NOTE 2: The logic is a bit adjusted (and duplicated yeah... not so DRY)
from cartridge.shop.page_processors.py
I hope this is helpful, however what I'm having here is slightly different,
because I'm working with `Product` model already implemented in cartridge.
You may skip the entire EXTRA_MODEL_FIELDS procedure, explained above.
Cheers!
On Saturday, March 8, 2014 11:55:14 AM UTC+2, Niels Jakob Buch wrote:
>
> Thanks Ed, your first approach was the one I started on, but not sure how
> to approach it in detail.
>
> Your second approach sounds more "normal" and I think the ownable idea
> from Lucian makes sense here. I think I will go with this. Still looking
> for examples though...any pointers?
>
--
You received this message because you are subscribed to the Google Groups
"Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.