Ok i think i might have figured it out, I needed to hook the save_related() 
method from BlogPostAdmin
not sure if this is the correct way tho, i just hooked into 
__getattribute__, and watched for any methods that looked useful

so i ended up adding the following to BlogPostAdmin

def save_related(self, request, form, formsets, change):
        aaa = super(BlogPostAdmin, self).save_related(request, form, 
formsets, change)
        cats = form.instance.categories.all()
        parents = []
        for a in cats:
            maxx = 10
            while a.parent_category != None and maxx > 0:
                parents.append(a.parent_category)
                a = a.parent_category
                maxx = maxx - 1
        for a in parents:
            form.instance.categories.add(a)
        return aaa

not sure if i need the loop counter, i just get nervous when using while 
loops lol

On Tuesday, August 25, 2015 at 12:12:02 AM UTC-4, Matt Hughes wrote:
>
>
> Hi when i add a blog post via the admin page, how do i validate the 
> categories?
>
> Ive tried overriding the 'clean()' method of BlogPost, which does get 
> called, but not sure where to check for categories.
>
> when i submit a post via the admin, i want to make sure it has atleast one 
> category.
> I have also modified my blogcategory model to include a 'parent_category' 
> field, and i want the make sure the BlogPost also includes all 
> parent_categories, so post with also be listed under these parent_categories
>
> Thanks!
>

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