Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Substitute Category model #34

Closed
fab10m opened this issue Mar 2, 2016 · 11 comments
Closed

Substitute Category model #34

fab10m opened this issue Mar 2, 2016 · 11 comments
Milestone

Comments

@fab10m
Copy link

fab10m commented Mar 2, 2016

Hi,

is there anyway substitute the puput category model with a custom one?
I'm trying to install puput over an existing django project. All has gone very well, but my project already has his own category model that can't be substitute.

Best,

Fabio

@marctc
Copy link
Collaborator

marctc commented Mar 2, 2016

Yeah, It can be done without many problems. However, you have to consider that you will need to modify the default templates and the entries filters in routes.py

@fab10m
Copy link
Author

fab10m commented Mar 2, 2016

Thanks for your prompt reply!
So, in order leave the snippet category as in puput, but pointing to "my" category, I only need to modify:

  • routes.py (where?)
  • default templates (which one?)
  • models.CategoryEntryPage?

Best,
Fabio

@marctc
Copy link
Collaborator

marctc commented Mar 2, 2016

routes.py (where?)

   @route(r'^category/(?P<category>[-\w]+)/$')
    def entries_by_category(self, request, category, *args, **kwargs):
        self.search_type = _('category')
        self.search_term = category
        self.entries = self.get_entries().filter(entry_categories__category__slug=category)
        return Page.serve(self, request, *args, **kwargs)

default templates (which one?)

templates/puput/tags/categories_list.html

models.CategoryEntryPage?

class CategoryEntryPage(models.Model):
    category = models.ForeignKey(Category, related_name="+", verbose_name=_('Category'))

@fab10m
Copy link
Author

fab10m commented Mar 2, 2016

Thank you very much Marc!
Do you plan to make the category customizable by the developers without edit your core code?

Fabio

@marctc
Copy link
Collaborator

marctc commented Mar 2, 2016

Yeah, why not? I have to study this feature and implement it in the cleaner way.

@fab10m
Copy link
Author

fab10m commented Mar 2, 2016

Great! I stay tuned then :-)

@fab10m
Copy link
Author

fab10m commented Mar 6, 2016

Hi Marc,

I made the following patches and anything seems to work:

  • I create an entry for the setings.py file PUPUT_CATEGORY_MODEL;
  • I commented the statement @register_snippet over the "Category" definition;
  • I changed the name of Category in CategoryDefault
  • I added this code under CategoryDefault definition
CategoryModel = import_model(getattr(settings, 'PUPUT_CATEGORY_MODEL', CategoryDefault))

@register_snippet
class Category(CategoryModel):
    objects = CategoryManager()

    class Meta:
        proxy = True
  • I made the following change the categories_list inclusion_tag (because I don't need nested Categories)
        if hasattr(Category, 'parent'):
            categories = Category.objects.with_uses(blog_page).filter(parent=None)
        else:
            categories = Category.objects.with_uses(blog_page).all()

Do you have any kind of suggestions?

Fabio

@marctc
Copy link
Collaborator

marctc commented Mar 7, 2016

I create an entry for the setings.py file PUPUT_CATEGORY_MODEL;

👍

I made the following patches and anything seems to work:

  • I create an entry for the setings.py file PUPUT_CATEGORY_MODEL;
  • I commented the statement @register_snippet over the "Category" definition;
  • I changed the name of Category in CategoryDefault
  • I added this code under CategoryDefault definition

Nice approach, but I think it will be better a pattern like EntryAbstract. You can define the default Category model in abstracts and define the actual Category in models.py like EntryPage.

  • I made the following change the categories_list inclusion_tag (because I don't need nested Categories)

👍

@fab10m
Copy link
Author

fab10m commented Mar 7, 2016

Thanks Mark!
I'm going to try to follow the approach suggested by you.

@marctc marctc added this to the 1.0 milestone Mar 20, 2016
@marctc
Copy link
Collaborator

marctc commented Jun 8, 2016

@fab10m any news regarding this issue?

@fab10m
Copy link
Author

fab10m commented Jul 30, 2016

Hi, @marctc I've no news. I'm stiill in the same situation of 5 months ago. Allora works fine, so I decided not to touch anything :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants