Joomla 2.5
I created the following structure of contact categories :
Category 1 (does not contain any contact)
SubCategory 11 (contains contacts, Parent = Category 1)
SubCategory 12 (contains contacts, Parent = Category 1)
Coming from a menu type "List Contacts in a Category" I want to show a Contact page as this :
SubCategory 11 :
Contact A
Contact B
SubCategory 12 :
Contact C
Contact D
I copied the Category tmpl files in the html folder of my template and now the page shows :
SubCategory 11
SubCategory 12
Now I need to modify the script to show for each SubCategory but I can't see how I can access the contact items
Could anybody help me ?
Gustav
Related
I have my website which displays the records on website these records are of different categories how can group the records belongs to similar category and display them together
category 1
List item 1
List item 2
List item 3
class Mymixin:
def get_queryset(self):
return Record.objects.all()
class Model:
category = models.Charfield(max_length=255, choices=RecordsCategory.choices(True, True)
Just... order the records by category?
On how to do that: that depends on the nature of your website, which you didn't disclose, but at the end it will come to appending
queryset = queryset.order_by('category')
to whatever queryset is feeding the website. Not that you need to write this as is: how this should be written will differ greatly depending on your actual site technology.
i have created a customize module to change the selling price because
i want the selling price to depend on the price of the supplier.
My problem is how to put the allocation of the value of the supplier price (price) in the price field (list_price) is made when clicking the save button after the creation of a new product because I noticed that the field "list_price" takes the value of the field "price" just after clicking on the button create a new product it means even before I enter the data of the field "price" (price of the supplier). In this way the value of the field "list_price" takes the value "0".
Any idea for help please?
product.py
from openerp import fields, models, api
class product(models.Model):
_inherit = 'product.template'
product_tmpl_id = fields.Many2one('product.template', string='Product')
list_price = fields.Float(string="Prix de vente", store=True, related='product_tmpl_id.seller_ids.price')
I will give my models first and then write description.
class Entry(models.Model):
entry_text = models.TextField()
class Category(models.Model):
user = models.ForeignKey(User)
category_text = models.CharField(max_length=200)
entries = models.ManyToManyField(Entry, through='CategoryEntry')
class CategoryEntry(models.Model):
category = models.ForeignKey(Category)
entry = models.ForeignKey(Entry)
viewed = models.BooleanField(default=False)
So I have Entry model and Category model, and I have created intermediate model CategoryEntry as descriebed here https://docs.djangoproject.com/en/1.7/topics/db/models/#extra-fields-on-many-to-many-relationships because I need one extra field "viewed" (marked as True when user for the first time opens specific Entry link).
So I have created generic.ListView view, where I show all these categories that user has created for himself. What I want, is to show next to every category name, how many entries there are and how many entries he hasn't viewed yet.
Like:
Category Total Not_viewed
AAA 126 5
BBB 17 15
I have managed to show total entries in template by
{% for category in categories %}
{{ category.text }}
{{ category.entries.count }}
{% endfor %}
In my view I have get_queryset like
def get_queryset(self):
categories = Category.objects.filter(user=self.request.user.id)[:]
return categories
As I understand, then the best way would somehow add this extra info about every categories entries viewed count in get_queryset. I have searched around but didn't found anything what works. Have tried some things with select_related, prefetch_related, annotate but don't get whats the right way to do this.
Know that it's not right, but tried something like that and some other things.
categories = Category.objects.filter(user=self.request.user.id).select_related('categoryentry').filter(categoryentry__viewed=False).count()
categories = Category.objects.filter(user=self.request.user.id).annotate(not_viewed_count=Count('categoryentry')).filter(not_viewed_count__viewed=False)
Hope you get my idea what I wan't to achieve.
In your CategoryEntry model, use related_name in the category field like so:
category = models.ForeignKey(Category, related_name="related_entry_categories")
Now you can use this related name when querying the Category model. For example:
from itertools import chain
categories_not_viewed = Category.objects.filter(user=self.request.user.id, related_entry_categories__viewed=False).annotate(num_not_viewed=Count('related_entry_categories'))
categories_viewed = Category.objects.filter(user=self.request.user.id, related_entry_categories__viewed=True).extra(select={'num_not_viewed': 0})
categories = chain(list(categories_not_viewed), list(categories_viewed))
At end I came up with this solution:
categories = Category.objects.filter(user=self.request.user.id).extra(select = {
"num_not_viewed" : """
SELECT COUNT(*)
FROM app_categoryentry
WHERE app_categoryentry.category_id = app_category.id
AND app_categoryentry.viewed = %d """ % 0,
})
Based on the solution from this resource http://timmyomahony.com/blog/filtering-annotations-django/
If anyone have other solution how the get the same result with only Django ORM, I would like to know.
I'm not sure why this is causing me such a problem but I can't seem to get it figured out. I've got a CSV and PDF export for products in our Mezzanine / Cartridge product DB. It exports each ProductVariation in a row. Works great but I need to add a filter that exports only published products for instance. ProductVariations have a foreignkey relation to the Product model:
class ProductVariation(Priced):
"""
A combination of selected options from
``SHOP_OPTION_TYPE_CHOICES`` for a ``Product`` instance.
"""
product = models.ForeignKey("Product", related_name="variations")
The product model subclasses Displayable:
class Product(Displayable, Priced, RichText, AdminThumbMixin):
"""
Container model for a product that stores information common to
all of its variations such as the product's title and description.
"""
The Displayable class is used to determine whether a product is displayed for normal users or staff only:
CONTENT_STATUS_DRAFT = 1
CONTENT_STATUS_PUBLISHED = 2
CONTENT_STATUS_COMPLETE = 3
CONTENT_STATUS_INACTIVE = 4
CONTENT_STATUS_CHOICES = (
(CONTENT_STATUS_DRAFT, _("Draft")),
(CONTENT_STATUS_PUBLISHED, _("Online")),
(CONTENT_STATUS_COMPLETE, _("Complete")),
(CONTENT_STATUS_INACTIVE, _("Inactive")),
)
class Displayable(Slugged, MetaData, TimeStamped):
"""
Abstract model that provides features of a visible page on the
website such as publishing fields. Basis of Mezzanine pages,
blog posts, and Cartridge products.
"""
status = models.IntegerField(_("Status"),
choices=CONTENT_STATUS_CHOICES, default=CONTENT_STATUS_DRAFT,
help_text=_("The General public can only view content that has ONLINE status."))
In trying to filter the results by Status however I can't seem to get it to work the way I expect. In my report view I'll add something like this:
product_variations = ProductVariation.objects.filter('product__status' == 'CONTENT_STATUS_PUBLISHED')
but it just gives me an error that "'bool' object is not iterable". What am I doing wrong?
When you write:
ProductVariation.objects.filter('product__status' == 'CONTENT_STATUS_PUBLISHED')
The expression 'product__status' == 'CONTENT_STATUS_PUBLISHED' becomes a boolean.
Right syntax is:
ProductVariation.objects.filter(product__status = 'CONTENT_STATUS_PUBLISHED')
I'm working on an application, where I am getting all categories through external api.
So now I need to get all subcategories for each category.
I have controller for that
CategoriesController = Ember.ArrayController.extend
#return all categories hits an api/categories
categories: (->
App.Category.find()
).property()
So now I need to get all subcategories for each category.
Basically we get subcategories from external api for each category.
so structure is
{"subcategories": [id: "1", name:"ss".. }
For this I have created another method to get subcategory for each category.
subcategories: ( ->
#get('categories').forEach (category) =>
##Get subcategories from external api
subcategories = App.Subcategory.find(category.id)
##making an array of objects
result = Ember.A()
result.pushObject({
category: categorys
subcategories: subcategories
)}
).property('#categories','#each')
so when I check subcategories it's always blank. What's wrong in it?
Thanks