joomla native function building multi-level category - joomla2.5

How to output a category like this using joomla native function. I am not using xml form to output the
Category 1
Category 9
Category 15
Category 16
Category 17
Category ...
Category 24
Category 10
etc...

Not sure, but maybe you need this function JHtmlMenu::treerecurse($id, $indent, $list, $children, $maxlevel = 9999, $level = 0, $type = 1).
You can find this function in this file /libraries/joomla/html/html/menu.php. This function can prepare a tree, but you need prepare template manually.

Related

Get n value with n parameter with Django Queryset

this is my first question. If my question is not clear, let me know :)
So I learn Django (learning by doing) for 4 Months in my project. I have one table name material, which is the table contains material name and price. Here I will describe my table:
id
materialName
price
1
Not Required
0
2
Material 1
123
3
Material 2
456
4
Material 3
900
I want to calculate the total material price by getting the price from the table. It looks ok if I only want to get 1 price only. But, I need to get 4 values of prices from what the user wants in input. Let's say the user chooses Material 3, Material 2, Not Required and Not Required. So there is 4 material price. Then, I use a queryset like this:
x = rawmaterial.objects.filter(Q(materialName = 'Material 3') | Q(materialName = 'Material 2') | Q(materialName = 'Not Required') | Q(materialName = 'Not Required')).values_list('price',flat=True)
but the result is (900, 456, 0) not like (900, 456, 0, 0). I have been trying with SQL query using OR, is there any possibility to get 4 values? Thank you :)
You can't query like that. Filter will filter out the values, not make them 0. Instead, you can use Conditional Expression. In your case, you can consider Case:
from django.db.models import Case, Value, When, F
rawmaterial.objects.annotate(
required_prices=Case(
When(materialName__in =['Material 3','Material 2', 'Not Required'], then=F('price')),
default=Value(0),
)
).values_list('required_prices', flat=True)
FYI, please follow the pep-8 style guide for naming class name (Pascal Case) and field/function names (snake case).

How to to get a list from a model based on function applied on a field without changing values in table

I am using Django and developing a Webapp, I have a model named People with different fields like, first_name,last_name, Familyid.
Values in column Familyid looks like this:
example familyids:
1
1.1
1.1.1
1.1.1.1
when i am creating view and get data in query set and displaying via template, i want to add one more column in query result set, with information FamilyID Dot Count i.e. Family ID contains how many docts "." , values like Dot Count = 1 or 2 or 3 and so on. please help either should i do it in template(HTMl) or inside view and return it as queryset, and how. Thanks
I would use #property:
class Person(models.Model):
...
family_id = models.CharField(...)
#property
def dot_count(self):
count = 0
for i in self.family_id:
if i == '.':
count += 1
return count
The, you can use dot_count like a property

filtering DateField on the basis of substring in django

So I am using a DateField for displaying the date. Which when passed to a template using contexts, renders in the format Nov. 4, 2018
Now there are multiple entries of such dates in the database. And I want to filter on the basis of string of the date actually shown. i.e when I type in Nov 4, or nov 4 or NOV 4 in my search input field, it should show the matched result. More like a substring match.
Now the only problem is that i do not know how to convert my_model.date field in to Nov. 4, 2018.
str(my_model.date) returns 2016-11-04 and I do not want to parse this with month_number-to-month_name map
I think, any of the two solutions should work.
1) Django filters that allow me to do so.
2) converting my_model.date into Nov. 4, 2018 string
Help please, been stuck on this forever now
Because you specifically mention rendering the date in a template, I'm not sure if the search operation you're referring to is a front-end, user-facing thing or a backend database query.
If you want to convert my_model.date to a prettier string before sending it to the template before display, you can process it in your view with strptime - this will give you the control that you're missing with the str wrapper: https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior While there are template tags that can do this for you as well, doing it in your view is faster and better.
If this is a DB query, then remember that you can filter date objects by their attributes. For example, to get all instances created on November 11th, 2011:
MyModel.objects.filter(
date__day = 11,
date__month = 11,
date__year = 2018
)
Note the double underscores.
Responding to your comment, now that I better understand your goal:
Date fields do not store their more "verbose" date information in a queryable spot. If you want to be able to query for things like "Nov" instead of 11 then you'll need to add another attribute (or attributes) to your model to propagate that computed data into queryable containers.
If it were me, I would do this within my_model:
from datetime import date
...
rawDate = models.DateField(...) #your current date field
formatted_month = models.CharField(...)
formatted_day = models.IntegerField(...)
formatted_year = models.IntegerField(...)
...
def save(self):
self.formatted_month = date.strftime(self.rawDate, '%b')
self.formatted_day = date.strftime(self.rawDate, '%d')
self.formatted_year = date.strftime(self.rawDate, '%Y')
super().save()
Now you can perform your NOV/nov/Nov lookup like so:
MyModel.objects.filter(
formatted_month__iexact = 'Nov'
)
This still requires you to split the month and day in your search term before hitting the database. If you wanted to squash these down a bit, you could instead store all of the formatted date info in a single field:
formatted_date = models.CharField(...)
...
def save(self):
self.formatted_date = date.strftime(self.rawDate, '%b %d %Y')
Then if your query looks like "NOV 4", you could do:
MyModel.objects.filter(formatted_date__icontains='NOV 4')

how to select multiple items from dropdown in autocomplete_light.MultipleChoiceField

I'm using autocomplete_light.MultipleChoiceField for multiple choice field. I'm able to get dropdown populated with values and for each value i need to enter the text and select values.
If I need to select 10 values from the drop down i need to type 10 times. Is there a way to enable/allow multiple select from download so that user needn't type in the regex in search field 10 times?
class HostGroupModelForm( autocomplete_light.ModelForm ):
hosts=autocomplete_light.MultipleChoiceField('HostAutocomplete')
class HostAutocomplete( autocomplete_light.AutocompleteModelBase ):
search_fields = [ 'hostname' ]
limit_choices = 75
choices = Host.objects.all()

Search by category in Opencart

I want to load all category names in an array after that check the input search field with array if found then go to that category page . How to get this done?
1) make one function in catalog\model\catalog\product.php,it will return all active category
2) load this function at catalog\controller\product\search.php at line 17
3) use in_array function to get result,searched title is in or not
4) redirection code if searched title is in category array
Thanks