Giter Site home page Giter Site logo

Substitute Category model about puput HOT 11 CLOSED

apsl avatar apsl commented on May 20, 2024
Substitute Category model

from puput.

Comments (11)

marctc avatar marctc commented on May 20, 2024

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

from puput.

fab10m avatar fab10m commented on May 20, 2024

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

from puput.

marctc avatar marctc commented on May 20, 2024

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

from puput.

fab10m avatar fab10m commented on May 20, 2024

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

Fabio

from puput.

marctc avatar marctc commented on May 20, 2024

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

from puput.

fab10m avatar fab10m commented on May 20, 2024

Great! I stay tuned then :-)

from puput.

fab10m avatar fab10m commented on May 20, 2024

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

from puput.

marctc avatar marctc commented on May 20, 2024

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)

👍

from puput.

fab10m avatar fab10m commented on May 20, 2024

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

from puput.

marctc avatar marctc commented on May 20, 2024

@fab10m any news regarding this issue?

from puput.

fab10m avatar fab10m commented on May 20, 2024

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

from puput.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.