2009/5/20 Oleg Oltar <[email protected]>

> Is there any doc I can read about it?
>
> On Wed, May 20, 2009 at 9:50 PM, Alex Gaynor <[email protected]>wrote:
>
>>
>>
>> 2009/5/20 Oleg Oltar <[email protected]>
>>
>>> Ok, I got it now
>>> What about the inheritance? Question 2?
>>>
>>> On Wed, May 20, 2009 at 9:30 PM, Alex Gaynor <[email protected]>wrote:
>>>
>>>>
>>>>
>>>> 2009/5/20 Oleg Oltar <[email protected]>
>>>>
>>>> Hi!
>>>>> I have a model with a Sections and Categories related this way:
>>>>>
>>>>> class Category(models.Model):
>>>>>     categoty = models.CharField(max_length=200)
>>>>>     name = models.CharField(max_length = 200, help_text=u"Имя
>>>>> категории")
>>>>>
>>>>>     def __unicode__(self):
>>>>>         return u"Категория %s" %self.name
>>>>>
>>>>> class Section(models.Model):
>>>>>     section = models.CharField(max_length=200, unique=True)
>>>>>     name = models.CharField(max_length=200, blank = True)
>>>>>     category = models.ForeignKey(Category, blank=True)
>>>>>
>>>>>     def __unicode__(self):
>>>>>         return u"%s" %(self.section)
>>>>>
>>>>>
>>>>> I passed a categories to the template. Is there a way I can display all
>>>>> sections related to each category in template?
>>>>>
>>>>> Not sure how to do it?
>>>>>
>>>>>  {% for category in categories  %}
>>>>>  <ul>
>>>>>   <li id="csstip" class="x"><a href="{{ category.category }}">{{
>>>>> category.name}}</a>
>>>>>     {% for section in %}
>>>>>                 But how to get all sections from one category?
>>>>>   </li>
>>>>>
>>>>> And the second question
>>>>>
>>>>> If I am passing a variable to the base template (I want to use the code
>>>>> to generate menu from categories), how to handle it in separate (extended
>>>>> templates)? E.g. do I have to query categories in each my view and pass it
>>>>> as value to all templates I use?
>>>>>
>>>>>
>>>>> Thanks in advance
>>>>> Oleg
>>>>>
>>>>>
>>>>>
>>>>>
>>>> {% for section in category_object.section_set.all %}
>>>>
>>>> {% endfor %}
>>>>
>>>> As documented here:
>>>> http://docs.djangoproject.com/en/dev/topics/db/queries/#many-to-many-relationships
>>>>
>>>> Alex
>>>>
>>>> --
>>>> "I disapprove of what you say, but I will defend to the death your right
>>>> to say it." --Voltaire
>>>> "The people's good is the highest law."--Cicero
>>>>
>>>>
>>>>
>>>
>>>
>>>
>> Right, there are 2 solutions to that (that I can think of).  1 is to write
>> a template context processor.  The other is to write a custom inclusion
>> template tag.  I personally favor the 2nd one because it gives you a little
>> bit more control.
>>
>>
>> Alex
>>
>> --
>> "I disapprove of what you say, but I will defend to the death your right
>> to say it." --Voltaire
>> "The people's good is the highest law."--Cicero
>>
>>
>>
>
> >
>
Right, sorry:

context processors:
http://www.b-list.org/weblog/2006/jun/14/django-tips-template-context-processors/

inclusion tag:
http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#inclusion-tags

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to