Hi Josh,

Thanks a lot for the reply. Yes that would ensure that the parent's 
category_type is copied to the child. But what if I want to set the 
category_type in the select field when the user is still creating the 
category? Any pointers on how to do that would be helpful.

On Thursday, June 12, 2014 7:09:02 PM UTC+5:30, Josh Cartmell wrote:
>
> Hey Preethi, why not just override the save method of Category.  The 
> following is pseudo code so it'll require some cleanup:
>
> class Category(Page):
>     """
>     A category for grouping activities
>     """
>     category_type = models.CharField(max_length=15, 
> choices=settings.CATEGORY_TYPES, default='M')
>
>     def save():
>         if self.parent and self.parent.content_type == 'category':
>             self.category_type = self.parent.category_type
>         super(Category, self).save()
>
>
> On Wed, Jun 11, 2014 at 3:02 PM, Preethi <[email protected] <javascript:>
> > wrote:
>
>>
>> Hi,
>>
>> I have a Category model that extends Page. It has a field category_type 
>> which can be one of two values. 
>> When a new child category is created I want to propagate the parent's 
>> category_type to the child. 
>> I know I have to write a custom form for the Category but I am lost. One 
>> way is to set the value of category_type to the parent's category_type and 
>> make the category_type field non-editable. How do I access the parent page 
>> in the Form? 
>> Any help is greatly appreciated.
>>
>>
>> class Category(Page):
>>     """
>>     A category for grouping activities
>>     """
>>      category_type = models.CharField(max_length=15, 
>> choices=settings.CATEGORY_TYPES, default='M')
>>
>>     class Meta:
>>         verbose_name = _("Category")
>>         verbose_name_plural = _("Categories")
>>         
>>         
>> class CategoryAdmin(PageAdmin):
>>     fieldsets = (
>>         (None, {
>>             "fields": ["title", "category_type"],
>>         }),
>>         (None, {
>>             "fields": ["status", ("publish_date", "expiry_date")],
>>         }),
>>         (_("Meta data"), {
>>             "fields": ["_meta_title", "slug", "in_sitemap"],
>>             "classes": ("collapse-closed",)
>>         }),
>>     )
>>     
>> Thanks in advance,
>> Preethi
>>
>> -- 
>> 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] <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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.

Reply via email to