I see you created a urlconf for your app, but have you added it to your
root urls.py? If so, is if above or below Mezzanine's catch-all pattern?

On Jul 6, 2017 9:12 PM, <marcusguttenp...@gmail.com> wrote:

> Hi, thanks for such a great resource! I have googled around for a few days
> and have made some headway this problem, but have hit a wall. I'm trying to
> use the Displayable model to create an easy way to add news stories and
> have them displayed as a simple list view, which is very similar behavior
> to the blog app. If there is a better solution using a ForeignKey, please
> point me in the right direction!
>
> I read an older post
> <https://groups.google.com/forum/#!msg/mezzanine-users/HmNGXkf4m4k/FDJ1Rd-h1KsJ>
>  about
> creating a new Displayable, and have used Mezzanine's source code to
> successfully extend the Displayable model and have it appear correctly in
> the admin. The issue now is that I can't seem to get the views (views.py)
> and url patterns to work. When clicked "view on site" from the admin, the
> url seems to grab the model's slug ("news"), but ends up linking to
> http://localhost:8000/en/admin/<myapp>/news/%28u/, and doesn't work
> linking directly to the actual item's slug. Exploring the source code for
> Mezzanine's blog's urls and views, I'm unsure how to correctly refactor. I
> understand that I will need to create my own templates to act as 
> blog_post_list.html
> and blog_post_detail.html, but don't know how to create the super basic
> views to point to them.
>
> models.py:
> class News(Displayable, RichText):
>
>     pagetitle = models.CharField('Title', max_length=255, blank=True)
>     url = models.CharField('Link', max_length=255, blank=True)
>     summary = models.CharField('Summary', max_length=255, blank=True)
>     date = models.DateField(_("Date"), default=datetime.date.today)
>     categories = models.ManyToManyField("NewsCategory",
>                                         verbose_name=_("Categories
> (Magazine, Award, etc.)"),
>                                         blank=True,
> related_name="newsitems")
>     related_news = models.ManyToManyField("self",
>                                  verbose_name=_("Related News"),
> blank=True)
>
>     class Meta:
>         verbose_name = _("News Item")
>         verbose_name_plural = _("News Items")
>
>     def get_absolute_url(self):
>         url_name = 'news'
>         kwargs = {
>             'slug': self.slug,
>         }
>         return (url_name, (), kwargs)
>
>
> class NewsCategory(Slugged):
>     """
>     A category for grouping news items into a series.
>     """
>
>     class Meta:
>         verbose_name = _("News Category")
>         verbose_name_plural = _("News Categories")
>         ordering = ("title",)
>
>     @models.permalink
>     def get_absolute_url(self):
>         return ("news_item_list_category", (), {"category": self.slug})
>
> admin.py
> news_fieldsets = deepcopy(DisplayableAdmin.fieldsets)
> news_fieldsets[0][1]["fields"].insert(1, "categories")
> news_fieldsets[0][1]["fields"].extend(["pagetitle", "url", "summary",
> "date"])
> news_fieldsets = list(news_fieldsets)
> news_fieldsets.insert(1, (_("Other News"), {
>     "classes": ("collapse-closed",),
>     "fields": ("related_news",)}))
> news_list_filter = deepcopy(DisplayableAdmin.list_filter) +
> ("categories",)
>
>
> class NewsAdmin(DisplayableAdmin):
>     """
>     Admin class for news posts.
>     """
>
>     fieldsets = news_fieldsets
>     # list_display = news_list_display
>     list_filter = news_list_filter
>     filter_horizontal = ("categories", "related_news",)
>
>     def save_form(self, request, form, change):
>         """
>         Super class ordering is important here - user must get saved first.
>         """
>         DisplayableAdmin.save_form(self, request, form, change)
>         return DisplayableAdmin.save_form(self, request, form, change)
>
> class NewsCategoryAdmin(BaseTranslationModelAdmin):
>     """
>     Admin class for blog categories. Hides itself from the admin menu
>     unless explicitly specified.
>     """
>
>     fieldsets = ((None, {"fields": ("title",)}),)
>
>     def has_module_permission(self, request):
>         """
>         Hide from the admin menu unless explicitly set in
> ``ADMIN_MENU_ORDER``.
>         """
>         for (name, items) in settings.ADMIN_MENU_ORDER:
>             if "blog.BlogCategory" in items:
>                 return True
>         return False
>
>
> admin.site.register(News, NewsAdmin)
> admin.site.register(NewsCategory, NewsCategoryAdmin)
>
> urls.py:
> from .models import News
> import .views
>
> _slashes = (
>     "/" if settings.BLOG_SLUG else "",
>     "/" if settings.APPEND_SLASH else "",
> )
>
> urlpatterns = patterns(
>     'news.views',
>     url("^%s(?P<slug>.*)%s$" % _slashes, "news", name="news"),
> )
>
> views.py:
> from django.shortcuts import render
>
> def news(request, slug):
>     return HttpResponse('Test')
>
> The view is currently not even returning "Test." Any direction at all
> would be appreciated!
>
>
> --
> 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 mezzanine-users+unsubscr...@googlegroups.com.
> 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 mezzanine-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to