How can I best create a blog that works similarly to Tumblr?

12 views
Skip to first unread message

Willy

unread,
Mar 30, 2012, 4:01:17 PM3/30/12
to django...@googlegroups.com
I know the question is kind of poorly phrased. But here goes, I've been working on a blog software and I want to have five distinct post types (in the same way Tumblr does) but I'm having a hard time figuring out how to create my index view and detail views as they are currently five different models that inherit from the same abstract base model.

Here is my models.py http://dpaste.com/724371/
as well as my views.py http://dpaste.com/724372/
and for safe measure, my urls.py within the app http://dpaste.com/724373/

How can I make this work? The current hack of using chain() isn't really working out because of the fact that it returns a list, not a queryset.
All together I feel like my code is quickly becoming unmaintainable but I would really like to know how to get this working as its early enough in the development to change.

Russell Keith-Magee

unread,
Mar 31, 2012, 1:46:06 AM3/31/12
to django...@googlegroups.com

On 31/03/2012, at 4:01 AM, Willy wrote:

> I know the question is kind of poorly phrased. But here goes, I've been working on a blog software and I want to have five distinct post types (in the same way Tumblr does) but I'm having a hard time figuring out how to create my index view and detail views as they are currently five different models that inherit from the same abstract base model.
>
> Here is my models.py http://dpaste.com/724371/
> as well as my views.py http://dpaste.com/724372/
> and for safe measure, my urls.py within the app http://dpaste.com/724373/
>
> How can I make this work? The current hack of using chain() isn't really working out because of the fact that it returns a list, not a queryset.

It sounds like most of your problems originate from the fact that you're using an abstract base class for posts.

If you make BasePost non-abstract, then you'll be able to generate a queryset of BasePost objects, rather than having to chain through querysets of the concrete subclasses. Once you have a BasePost instance, you can retrieve the specific details associated with each instance with a single attribute request. It also means that when you start introducing links to posts, you won't need to maintain 5 different foreign key types (i.e., link to a text post, link to an image post, etc) -- there's just one "link to a post".

The detail view is also simplified -- it's a detail view for BasePost, not some hybrid that is trying to handle 5 different subclasses.

The only other thing you might want to change is to make post_type a field on BasePost; this isn't strictly required, but it will make it easier to do CORBA-style "narrowing" (i.e., I have a BasePost instance; what type of Post is it, and how do I get an object of that type?).

Hope this helps!

Yours,
Russ Magee %-)

Willy Cordeiro

unread,
Mar 31, 2012, 4:46:42 AM3/31/12
to django...@googlegroups.com
Thanks for the reply! I'll try that, I had asked the same question on IRC at #django and I got no real results. I'll try this and see how it works. :)
-Wellington "Willy" Cordeiro



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.


Reply all
Reply to author
Forward
0 new messages