django-zinnia integration with existing django website - permissions, model access etc - python

I have built a django website, which requires blog functionality. Rather than roll my own, I have decided to use django-zinnia, to provide blog functionality for my site.
I have managed to change the template to integrate more closely, with the pages on my existing site - however, there are still things I haven't managed yet - to do.
I have come come across zinnia template tags, but they are not giving me the full level of access that I need.
Specifically, I need to do the following:
Access to properties of post (i.e. "entries" in Zinnia lingo) and comments so that I can display the following items on my home page:
Show thumbnails of last N posts (or most popular posts for example)
Show last X comments
Programatically create new posts - and specify the state of the post, i.e. draft/published
Restrict viewing certain posts to authenticated users belonging to a specific django user group.
Am I able to get this tight integration between Zinnia and my django website - or am I better of writing my own blog app, with the requested features?

Related

Knowing when's best to use Wagtail Pages or Django Models for Wagtail website

I am making a website running wagtail as the CMS/backend and use Page for things that are actual web pages on the site. In addition to this I will need an Events section and I am unsure whether to make it as a Wagtail Page or Django models.Model.
The way I would like this to work for the user is to have an Events section in the admin panel using ModelAdmin so that the user can easily find and navigate to all Events, and, for those events to be displayed in various sections of the site - Home Page, Events Page, Article Page for example.
I think using Page for this and requiring the user to navigate to it (Home > Events Listing > Event Detail) each time is rather a waste of time and cumbersome as opposed to having it use ModelAdmin paired with Django models.Model and that being 1 or 2 clicks away.
Reading through my question it's obvious I am leaning towards using Django model for this, so my question is: what is the trade-off between the two? Is there a set use case for using one or the other? Would using one mean having more/less functionality over the other and what would those be?
Note: I know my question is almost identical to Guidelines for using Wagtail Pages or Django models? however it's more focused on ecommerce but most importantly it has no answer.
Use models.Model and register as a snippet because it will give you more flexibility.
As a user mentioned above, using a snippet is a great idea for what you're discussing. It's one click on the admin and they're in the event system. Then, you can just pass that model into the context for a page. Here's an example of doing this in Wagtail. See this example on adding snippets as streamfield if you wanted the customer to be able to place the events manually through the CMS.

Django modelform: Create new related object

I've been searching stack overflow and google for a solution for over an hour now, and I can't seem to find something that, in my opinion, should be easy to obtain (as it's a common use case).
I've checked this thread, and a few others, but I haven't been able to find a real, easy solution:
Django modelform: is inline adding related model possible?
Anyway, say I have a model with three related entities, two foreign keys and a many-to-many related class. Now, I have a ModelForm which displays these in comboboxes and lists, but what I need is that "+" button next to these elements (as seen in the admin interface).
I want the plus to take me to a new form, for that particular entity, allow me to submit the new information, create the database entry, take me back to my original form and have the newly added entity selected in the combobox. I'm really hoping the django ModelForm Meta class has an attribute that I can't seem to find which enables exactly this.
This isn't really a django question.
This has to do with presentation of a particular widget in an html document, and that is governed by either the HTML markup, CSS, or javascript.
Django is a server side application and is primarily responsible for creating a valid http response and receiving a valid http request (of course, there is a lot that happens in the interim and that is why django is so big) but it's not a "one toolkit to kill them all" app.
I think you want to look at bootstrap: http://getbootstrap.com/
Jquery UI: http://jqueryui.com/
Or some combination of the two.
You can also just mark up the document yourself with a stock img or something.
However, if you want to do it exactly how the admin does it, just go into django.contrib.admin and examin the code to figure out how the django developers did it. I believe they are just using Jquery UI and some manual markup to accomplish that.

Make user-submitted links live (i.e. clickable) in a django app

This question is for django ninjas: I have an app (djagno 1.4) that allows users to create posts. These posts have a number of fields, including several CharFields.
My problem is this: when a user creates a new post and pastes a live link into one of these post CharFields, I want that link to be live and clickable as soon as its up. On doing some research I saw here how to deal with the same problem in php.
Can someone help me out, or point me in the right direction to some documentation? I can't find any on this topic.
What you want is the urlize filter, so, let's say your Post model has a field called text, then in your template you'd do this:
{{ post_obj.text|urlize }}

What are the best uses for the Django Admin app?

On the website, it says this:
One of the most powerful parts of
Django is the automatic admin
interface. It reads metadata in your
model to provide a powerful and
production-ready interface that
content producers can immediately use
to start adding content to the site.
In this document, we discuss how to
activate, use and customize Django’s
admin interface.admin interface.
So what? I still don't understand what the Admin interface is used for. Is it like a PHPMYADMIN? Why would I ever need this?
Let's say you create a model called Entry. IE an extremely simple blog. You write a view to show all the entries on the front page. Now how do you put those entries on the webpage? How do you edit them?
Enter the admin. You register your model with the admin, create a superuser and log in to your running webapp. It's there, with a fully functional interface for creating the entries.
Some of the uses I can think of -
Editing data or Adding data. If you have any sort of data entry tasks, the admin app handles it like a breeze. Django’s admin especially shines when non-technical users need to be able to enter data.
If you have understood above point, then this makes it possible for programmers to work along with designers and content producers!
Permissions - An admin interface can be used to give permissions, create groups with similar permissions, make more than one administrators etc. (i.e. if you have a login kinda site).
Inspecting data models - when I have defined a new model, I call it up in the admin and enter some dummy data.
Managing acquired data - basically what a moderator does in case of auto-generated content sites.
Block out buggy features - Also if you tweak it a little, you can create an interface wherein say some new feature you coded is buggy. You could disable it from admin interface.
Think of the power this gives in a big organization where everyone need not know programming.

How do I form a URL in Django for what I'm doing

Desperate, please help. Will work for food :)
I want to be able to have pages at the following URLs, and I want to be able to look them up by their URL (ie, If somebody goes to a certain URL, I want to be able to check for a page there).
mysite.com/somepage/somesubpage/somesubsubpage/
mysite.com/somepage/somesubpage/anothersubpage/
mysite.com/somepage/somesubpage/somesubpage/
mysite.com/somepage/somepage/
Notice I want to be able to reuse each page's slug (ie, somepage/somepage). Of course each slug will be unique for it's level (ie, cannot have two pages with mysite.com/somepage/other/ and mysite.com/somepage/other/ because they would in essence be the same page). What is a good way to do this. I've tried to store the slug for a page ('somesubpage') in a field called 'slug', and make each slug unique for it's parent page so that the above circumstance can't happen. The problem with this is that if I try to look up a page by it's slug (ie, 'somepage'), and there happens to be a page at mysite.com/other/somepage/ and mysite.com/page/somepage/, how would my application know which one to get (they both have the same slug 'somepage').
You need to also store level and parent attributes, so that you can always get the right object.
The requirement to store hierarchical data comes up very frequently, and I always recommend django-mptt. It's the Django implementation of an efficient algorithm for storing hierarchical data in a database. I've used it on several projects. Basically, as well as storing level and parent, it also stores a left and right for each object, so that it can describe the tree and all its sub-elements uniquely. There are some explanatory links on the project's home page.
It sounds like you're looking for a CMS app. There's a comparison of several Django-based CMS. If you want a full-featured CMS at the center of your project, DjangoCMS 2 or django-page-cms might be the right fit. If you prefer a CMS that supports the basic CMS use cases but goes out of your way most of the time feincms could be something to look at.
edit: incidentally, most of the CMS on the comparision page use django-mptt that Daniel mentions.

Categories

Resources